]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/class.cpp
Update clang to r104832.
[FreeBSD/FreeBSD.git] / test / SemaCXX / class.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s 
2 class C {
3 public:
4   auto int errx; // expected-error {{error: storage class specified for a member declaration}}
5   register int erry; // expected-error {{error: storage class specified for a member declaration}}
6   extern int errz; // expected-error {{error: storage class specified for a member declaration}}
7
8   static void sm() {
9     sx = 0;
10     this->x = 0; // expected-error {{error: invalid use of 'this' outside of a nonstatic member function}}
11     x = 0; // expected-error {{error: invalid use of member 'x' in static member function}}
12   }
13
14   class NestedC {
15     void m() {
16       sx = 0;
17       x = 0; // expected-error {{error: invalid use of nonstatic data member 'x'}}
18     }
19   };
20
21   int b : 1, w : 2;
22   int : 1, : 2;
23   typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
24   static int sb : 1; // expected-error {{error: static member 'sb' cannot be a bit-field}}
25   static int vs;
26
27   typedef int func();
28   func tm;
29   func *ptm;
30   func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
31   NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
32
33   enum E1 { en1, en2 };
34
35   int i = 0; // expected-error {{error: 'i' can only be initialized if it is a static const integral data member}}
36   static int si = 0; // expected-error {{error: 'si' can only be initialized if it is a static const integral data member}}
37   static const NestedC ci = 0; // expected-error {{error: 'ci' can only be initialized if it is a static const integral data member}}
38   static const int nci = vs; // expected-error {{in-class initializer is not an integral constant expression}}
39   static const int vi = 0;
40   static const E evi = 0;
41
42   void m() {
43     sx = 0;
44     this->x = 0;
45     y = 0;
46     this = 0; // expected-error {{error: expression is not assignable}}
47   }
48
49   int f1(int p) {
50     A z = 6;
51     return p + x + this->y + z;
52   }
53
54   typedef int A;
55
56   virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
57   virtual static int vsif(); // expected-error {{error: 'virtual' can only appear on non-static member functions}}
58   virtual int vif();
59
60 private:
61   int x,y;
62   static int sx;
63
64   mutable int mi;
65   mutable int &mir; // expected-error {{error: 'mutable' cannot be applied to references}}
66   mutable void mfn(); // expected-error {{error: 'mutable' cannot be applied to functions}}
67   mutable const int mci; // expected-error {{error: 'mutable' and 'const' cannot be mixed}}
68
69   static const int number = 50;
70   static int arr[number];
71 };
72
73 class C2 {
74   void f() {
75     static int lx;
76     class LC1 {
77       int m() { return lx; }
78     };
79     class LC2 {
80       int m() { return lx; }
81     };
82   }
83 };
84
85 struct C3 {
86   int i;
87   mutable int j;
88 };
89 void f()
90 {
91   const C3 c3 = { 1, 2 };
92   (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'int const *' to 'int *' is not allowed}}
93   // but no error here
94   (void)static_cast<int*>(&c3.j);
95 }
96
97 // Play with mutable a bit more, to make sure it doesn't crash anything.
98 mutable int gi; // expected-error {{error: 'mutable' can only be applied to member variables}}
99 mutable void gfn(); // expected-error {{illegal storage class on function}}
100 void ogfn()
101 {
102   mutable int ml; // expected-error {{error: 'mutable' can only be applied to member variables}}
103
104   // PR3020: This used to crash due to double ownership of C4.
105   struct C4;
106   C4; // expected-warning {{declaration does not declare anything}}
107 }
108
109 struct C4 {
110   void f(); // expected-note{{previous declaration is here}}
111   int f; // expected-error{{duplicate member 'f'}}
112 };
113
114 // PR5415 - don't hang!
115 struct S
116 {
117   void f(); // expected-note 1 {{previous declaration}}
118   void S::f() {} // expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
119   void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
120 };
121
122 // Don't crash on this bogus code.
123 namespace pr6629 {
124   // TODO: most of these errors are spurious
125   template<class T1, class T2> struct foo :
126     bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \
127                        // BOGUS expected-error {{expected '{' after base class list}} \
128                        // BOGUS expected-error {{expected ';' after struct}} \
129                        // BOGUS expected-error {{expected unqualified-id}} \
130   { };
131
132   template<> struct foo<unknown,unknown> { // why isn't there an error here?
133     template <typename U1, typename U2> struct bar {
134       typedef bar type;
135       static const int value = 0;
136     };
137   };
138 }
139
140 namespace PR7153 {
141   class EnclosingClass {
142   public:
143     struct A { } mutable *member;
144   };
145  
146   void f(const EnclosingClass &ec) {
147     ec.member = 0;
148   }
149 }
150
151 namespace PR7196 {
152   struct A {
153     int a;
154
155     void f() {
156       char i[sizeof(a)];
157       enum { x = sizeof(i) };
158       enum { y = sizeof(a) };
159     }
160   };
161 }