xref: /llvm-project/clang/test/CXX/class/class.mem/p1.cpp (revision 2194fb6ed95595b39ec0132769e021c874adcacc)
12c7d9290SDouglas Gregor // RUN: %clang_cc1 -fsyntax-only -verify %s
22c7d9290SDouglas Gregor 
32c7d9290SDouglas Gregor struct S
42c7d9290SDouglas Gregor {
52c7d9290SDouglas Gregor   static int v1; // expected-note{{previous declaration is here}}
62c7d9290SDouglas Gregor   int v1; //expected-error{{duplicate member 'v1'}}
72c7d9290SDouglas Gregor   int v;  //expected-note 2{{previous definition is here}} \
82c7d9290SDouglas Gregor           // expected-note{{previous declaration is here}}
92c7d9290SDouglas Gregor   static int v; //expected-error{{redefinition of 'v' as different kind of symbol}}
102c7d9290SDouglas Gregor   int v; //expected-error{{duplicate member 'v'}}
112c7d9290SDouglas Gregor   static int v; //expected-error{{redefinition of 'v' as different kind of symbol}}
12*2194fb6eSRichard Smith   enum EnumT { E = 10 }; // expected-note {{declared here}}
132c7d9290SDouglas Gregor   friend struct M;
142c7d9290SDouglas Gregor   struct X;  //expected-note{{forward declaration of 'S::X'}}
152c7d9290SDouglas Gregor   friend struct X;
162c7d9290SDouglas Gregor };
172c7d9290SDouglas Gregor 
182c7d9290SDouglas Gregor S::EnumT Evar = S::E; // ok
19*2194fb6eSRichard Smith S::EnumT Evar2 = EnumT(); //expected-error{{use of undeclared identifier 'EnumT'; did you mean 'S::EnumT'?}}
202c7d9290SDouglas Gregor S::M m; //expected-error{{no type named 'M' in 'S'}}
212c7d9290SDouglas Gregor S::X x; //expected-error{{variable has incomplete type 'S::X'}}
222c7d9290SDouglas Gregor 
232c7d9290SDouglas Gregor 
242c7d9290SDouglas Gregor struct S2
252c7d9290SDouglas Gregor {
262c7d9290SDouglas Gregor   static int v2; // expected-note{{previous declaration is here}}
272c7d9290SDouglas Gregor   static int v2; //expected-error{{duplicate member 'v2'}}
282c7d9290SDouglas Gregor };
292c7d9290SDouglas Gregor 
302c7d9290SDouglas Gregor struct S3
312c7d9290SDouglas Gregor {
322c7d9290SDouglas Gregor   static int v3;
332c7d9290SDouglas Gregor   struct S4
342c7d9290SDouglas Gregor   {
352c7d9290SDouglas Gregor     static int v3;
362c7d9290SDouglas Gregor   };
372c7d9290SDouglas Gregor };
382c7d9290SDouglas Gregor 
392c7d9290SDouglas Gregor struct S4
402c7d9290SDouglas Gregor {
412c7d9290SDouglas Gregor   static int v4;
422c7d9290SDouglas Gregor };
432c7d9290SDouglas Gregor 
442c7d9290SDouglas Gregor int S4::v4; //expected-note{{previous definition is here}}
452c7d9290SDouglas Gregor int S4::v4; //expected-error{{redefinition of 'v4'}}
462c7d9290SDouglas Gregor 
472c7d9290SDouglas Gregor struct S5
482c7d9290SDouglas Gregor {
492c7d9290SDouglas Gregor   static int v5; //expected-note{{previous definition is here}}
v5S5502c7d9290SDouglas Gregor   void v5() { } //expected-error{{redefinition of 'v5' as different kind of symbol}}
512c7d9290SDouglas Gregor 
v6S5522c7d9290SDouglas Gregor   void v6() { } //expected-note{{previous definition is here}}
532c7d9290SDouglas Gregor   static int v6; //expected-error{{redefinition of 'v6' as different kind of symbol}}
542c7d9290SDouglas Gregor 
v7S5552c7d9290SDouglas Gregor   void v7() { }
v7S5562c7d9290SDouglas Gregor   void v7(int) { } //expected-note{{previous definition is here}}
572c7d9290SDouglas Gregor   static int v7;  //expected-error{{redefinition of 'v7' as different kind of symbol}}
582c7d9290SDouglas Gregor 
592c7d9290SDouglas Gregor   void v8();
602c7d9290SDouglas Gregor   int v8(int); //expected-note{{previous declaration is here}}
612c7d9290SDouglas Gregor   int v8; //expected-error{{duplicate member 'v8'}}
622c7d9290SDouglas Gregor 
632c7d9290SDouglas Gregor 
642c7d9290SDouglas Gregor };
65758cb67fSDouglas Gregor 
66758cb67fSDouglas Gregor namespace PR8245 {
67758cb67fSDouglas Gregor   class X {
68758cb67fSDouglas Gregor   public:
69758cb67fSDouglas Gregor     template<class C>
70758cb67fSDouglas Gregor     class Inner {
71758cb67fSDouglas Gregor     public:
72758cb67fSDouglas Gregor       void foo(bool bar = true);
73758cb67fSDouglas Gregor       int bam;
74758cb67fSDouglas Gregor     };
75758cb67fSDouglas Gregor 
76758cb67fSDouglas Gregor     Inner<int> _foo;
77758cb67fSDouglas Gregor   };
78758cb67fSDouglas Gregor 
f()79758cb67fSDouglas Gregor   void f() {
80758cb67fSDouglas Gregor     X::Inner<int> c2i;
81758cb67fSDouglas Gregor     X::Inner<float> c2f;
82758cb67fSDouglas Gregor     c2i.foo();
83758cb67fSDouglas Gregor     c2f.foo();
84758cb67fSDouglas Gregor   }
85758cb67fSDouglas Gregor 
86758cb67fSDouglas Gregor   class Y {
87758cb67fSDouglas Gregor     class Inner {
88758cb67fSDouglas Gregor       void foo(int = sizeof(Y));
89758cb67fSDouglas Gregor     };
90758cb67fSDouglas Gregor   };
91758cb67fSDouglas Gregor }
92