Debian Codegraph @

clang/test/Sema/decl-hidden-in-c++.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++-hidden-decl %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++-compat %s
3 // RUN: %clang_cc1 -fsyntax-only -verify=good %s
4 // RUN: %clang_cc1 -fsyntax-only -verify=cxx -x c++ -std=c++2c %s
5 // good-no-diagnostics
6
7 struct A {
8 struct B { // #b-decl
9 int x;
10 } bs;
11 enum E { // #e-decl
12 One
13 } es;
14 int y;
15 };
16
17 struct C {
18 struct D {
19 struct F { // #f-decl
20 int x;
21 } f;
22 } d;
23 };
24
25 struct B b; // expected-warning {{struct defined within a struct or union is not visible in C++}} \
26 expected-note@#b-decl {{declared here}} \
27 cxx-error {{variable has incomplete type 'struct B'}} \
28 cxx-note 3 {{forward declaration of 'B'}}
29 enum E e; // expected-warning {{enum defined within a struct or union is not visible in C++}} \
30 expected-note@#e-decl {{declared here}} \
31 cxx-error {{ISO C++ forbids forward references to 'enum' types}} \
32 cxx-error {{variable has incomplete type 'enum E'}} \
33 cxx-note 3 {{forward declaration of 'E'}}
34 struct F f; // expected-warning {{struct defined within a struct or union is not visible in C++}} \
35 expected-note@#f-decl {{declared here}} \
36 cxx-error {{variable has incomplete type 'struct F'}} \
37 cxx-note {{forward declaration of 'F'}}
38
39 void func(struct B b); // expected-warning {{struct defined within a struct or union is not visible in C++}} \
40 expected-note@#b-decl {{declared here}}
41 void other_func(enum E e) { // expected-warning {{enum defined within a struct or union is not visible in C++}} \
42 expected-note@#e-decl {{declared here}} \
43 cxx-error {{variable has incomplete type 'enum E'}}
44 struct B b; // expected-warning {{struct defined within a struct or union is not visible in C++}} \
45 expected-note@#b-decl {{declared here}} \
46 cxx-error {{variable has incomplete type 'struct B'}}
47 }
48
49 struct X {
50 struct B b; // expected-warning {{struct defined within a struct or union is not visible in C++}} \
51 expected-note@#b-decl {{declared here}} \
52 cxx-error {{field has incomplete type 'struct B'}}
53 enum E e; // expected-warning {{enum defined within a struct or union is not visible in C++}} \
54 expected-note@#e-decl {{declared here}} \
55 cxx-error {{field has incomplete type 'enum E'}}
56 };
57
58 struct Y {
59 struct Z1 {
60 int x;
61 } zs;
62
63 struct Z2 {
64 // This is fine, it is still valid C++.
65 struct Z1 inner_zs;
66 } more_zs;
67 };
68