p2-0x.cpp revision b4e85ed51905fc94378d7b4ff62b06e0d08042b7
1d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com// RUN: %clang_cc1 -fsyntax-only -std=c++11 -pedantic -verify -fcxx-exceptions %s -fconstexpr-depth 128
2d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com
3d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com// A conditional-expression is a core constant expression unless it involves one
4d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com// of the following as a potentially evaluated subexpression [...]:
5d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com
6d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com// - this (5.1.1 [expr.prim.general]) [Note: when evaluating a constant
7d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com//   expression, function invocation substitution (7.1.5 [dcl.constexpr])
8d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com//   replaces each occurrence of this in a constexpr member function with a
9d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com//   pointer to the class object. -end note];
10d26147adbbdca85f07dff432025afee0c8614387caryclark@google.comstruct This {
11d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com  int this1 : this1; // expected-error {{undeclared}}
12d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com  int this2 : this->this1; // expected-error {{invalid}}
13d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com  void this3() {
14d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com    int n1[this->this1]; // expected-warning {{variable length array}}
15d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com    int n2[this1]; // expected-warning {{variable length array}}
16d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com    (void)n1, (void)n2;
17d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com  }
18d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com};
19d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com
20d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com// - an invocation of a function other than a constexpr constructor for a
21d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com//   literal class or a constexpr function [ Note: Overload resolution (13.3)
22a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   is applied as usual - end note ];
23a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comstruct NonConstexpr1 {
24a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  static int f() { return 1; } // expected-note {{here}}
25a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int n : f(); // expected-error {{constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
26a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com};
27a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comstruct NonConstexpr2 {
28a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr NonConstexpr2(); // expected-note {{here}}
29a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int n;
30a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com};
31a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comstruct NonConstexpr3 {
32a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  NonConstexpr3();
33a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int m : NonConstexpr2().n; // expected-error {{constant expression}} expected-note {{undefined constructor 'NonConstexpr2'}}
34a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com};
3572ae6bd24eb72be13d5745129c16058e4d54e2f4scroggo@google.comstruct NonConstexpr4 {
36a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  NonConstexpr4(); // expected-note {{declared here}}
37a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int n;
38a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com};
39a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comstruct NonConstexpr5 {
40a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int n : NonConstexpr4().n; // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr4' cannot be used in a constant expression}}
41a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com};
42a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
43a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com// - an invocation of an undefined constexpr function or an undefined
44a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   constexpr constructor;
45088719ecdc89b399dd3a3a65f8cced262e50d951robertphillips@google.comstruct UndefinedConstexpr {
46a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr UndefinedConstexpr();
47a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  static constexpr int undefinedConstexpr1(); // expected-note {{here}}
48a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  int undefinedConstexpr2 : undefinedConstexpr1(); // expected-error {{constant expression}} expected-note {{undefined function 'undefinedConstexpr1' cannot be used in a constant expression}}
49d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com};
50a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
51a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com// - an invocation of a constexpr function with arguments that, when substituted
52a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   by function invocation substitution (7.1.5), do not produce a constant
53a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   expression;
54a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comnamespace NonConstExprReturn {
55a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  static constexpr const int &id_ref(const int &n) {
56a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    return n; // expected-note {{reference to temporary cannot be returned from a constexpr function}}
57a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  }
58a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  struct NonConstExprFunction {
59a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    int n : id_ref( // expected-error {{constant expression}} expected-note {{in call to 'id_ref(16)'}}
60a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com        16 // expected-note {{temporary created here}}
61a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com        );
6272ae6bd24eb72be13d5745129c16058e4d54e2f4scroggo@google.com  };
63a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr const int *address_of(const int &a) {
64a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    return &a; // expected-note {{pointer to 'n' cannot be returned from a constexpr function}}
65a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  }
66a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr const int *return_param(int n) { // expected-note {{declared here}}
67a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    return address_of(n); // expected-note {{in call to 'address_of(n)'}}
68a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  }
69a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  struct S {
70a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    int n : *return_param(0); // expected-error {{constant expression}} expected-note {{in call to 'return_param(0)'}}
71a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  };
72941ee9303b62163ae08bbdcd7ad514e1a6389bdarobertphillips@google.com}
73a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
74a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com// - an invocation of a constexpr constructor with arguments that, when
75a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   substituted by function invocation substitution (7.1.5), do not produce all
76a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   constant expressions for the constructor calls and full-expressions in the
77a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com//   mem-initializers (including conversions);
78a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.comnamespace NonConstExprCtor {
79a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  struct T {
80a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    constexpr T(const int &r) :
81a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com      r(r) { // expected-note 2{{reference to temporary cannot be used to initialize a member in a constant expression}}
825370cd969d8f3957e4306068e6195ac1bca3d6cddjsollen@google.com    }
835370cd969d8f3957e4306068e6195ac1bca3d6cddjsollen@google.com    const int &r;
845370cd969d8f3957e4306068e6195ac1bca3d6cddjsollen@google.com  };
855370cd969d8f3957e4306068e6195ac1bca3d6cddjsollen@google.com  constexpr int n = 0;
86a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr T t1(n); // ok
87a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  constexpr T t2(0); // expected-error {{must be initialized by a constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'T(0)'}}
88a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com
89a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com  struct S {
90a2ca41e3afdd8fad5e0e924dec029f33918e0a67djsollen@google.com    int n : T(4).r; // expected-error {{constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'T(4)'}}
91d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com  };
92d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com}
93d26147adbbdca85f07dff432025afee0c8614387caryclark@google.com
94// - an invocation of a constexpr function or a constexpr constructor that would
95//   exceed the implementation-defined recursion limits (see Annex B);
96namespace RecursionLimits {
97  constexpr int RecurseForever(int n) {
98    return n + RecurseForever(n+1); // expected-note {{constexpr evaluation exceeded maximum depth of 128 calls}} expected-note 9{{in call to 'RecurseForever(}} expected-note {{skipping 118 calls}}
99  }
100  struct AlsoRecurseForever {
101    constexpr AlsoRecurseForever(int n) :
102      n(AlsoRecurseForever(n+1).n) // expected-note {{constexpr evaluation exceeded maximum depth of 128 calls}} expected-note 9{{in call to 'AlsoRecurseForever(}} expected-note {{skipping 118 calls}}
103    {}
104    int n;
105  };
106  struct S {
107    int k : RecurseForever(0); // expected-error {{constant expression}} expected-note {{in call to}}
108    int l : AlsoRecurseForever(0).n; // expected-error {{constant expression}} expected-note {{in call to}}
109  };
110}
111
112// FIXME:
113// - an operation that would have undefined behavior [Note: including, for
114//   example, signed integer overflow (Clause 5 [expr]), certain pointer
115//   arithmetic (5.7 [expr.add]), division by zero (5.6 [expr.mul]), or certain
116//   shift operations (5.8 [expr.shift]) -end note];
117namespace UndefinedBehavior {
118  void f(int n) {
119    switch (n) {
120    case (int)4.4e9: // expected-error {{constant expression}} expected-note {{value 4.4E+9 is outside the range of representable values of type 'int'}}
121    case (int)(unsigned)(long long)4.4e9: // ok
122    case (float)1e300: // expected-error {{constant expression}} expected-note {{value 1.0E+300 is outside the range of representable values of type 'float'}}
123    case (int)((float)1e37 / 1e30): // ok
124    case (int)(__fp16)65536: // expected-error {{constant expression}} expected-note {{value 65536 is outside the range of representable values of type 'half'}}
125      break;
126    }
127  }
128
129  struct S {
130    int m;
131  };
132  constexpr S s = { 5 }; // expected-note {{declared here}}
133  constexpr const int *p = &s.m + 1;
134  constexpr const int &f(const int *q) {
135    return q[0]; // expected-note {{dereferenced pointer past the end of subobject of 's' is not a constant expression}}
136  }
137  struct T {
138    int n : f(p); // expected-error {{not an integer constant expression}} expected-note {{in call to 'f(&s.m + 1)'}}
139  };
140
141  namespace Ptr {
142    struct A {};
143    struct B : A { int n; };
144    B a[3][3];
145    constexpr B *p = a[0] + 4; // expected-error {{constant expression}} expected-note {{element 4 of array of 3 elements}}
146    B b = {};
147    constexpr A *pa = &b + 1; // expected-error {{constant expression}} expected-note {{base class of pointer past the end}}
148    constexpr B *pb = (B*)((A*)&b + 1); // expected-error {{constant expression}} expected-note {{derived class of pointer past the end}}
149    constexpr const int *pn = &(&b + 1)->n; // expected-error {{constant expression}} expected-note {{field of pointer past the end}}
150    constexpr B *parr = &a[3][0]; // expected-error {{constant expression}} expected-note {{array element of pointer past the end}}
151
152    constexpr A *na = nullptr;
153    constexpr B *nb = nullptr;
154    constexpr A &ra = *nb; // expected-error {{constant expression}} expected-note {{cannot access base class of null pointer}}
155    constexpr B &rb = (B&)*na; // expected-error {{constant expression}} expected-note {{cannot access derived class of null pointer}}
156    static_assert((A*)nb == 0, "");
157    static_assert((B*)na == 0, "");
158    constexpr const int &nf = nb->n; // expected-error {{constant expression}} expected-note {{cannot access field of null pointer}}
159    constexpr const int &np = (*(int(*)[4])nullptr)[2]; // expected-error {{constant expression}} expected-note {{cannot access array element of null pointer}}
160  }
161}
162
163// - a lambda-expression (5.1.2);
164struct Lambda {
165  // FIXME: clang crashes when trying to parse this! Revisit this check once
166  // lambdas are fully implemented.
167  //int n : []{ return 1; }();
168};
169
170// - an lvalue-to-rvalue conversion (4.1) unless it is applied to
171namespace LValueToRValue {
172  // - a non-volatile glvalue of integral or enumeration type that refers to a
173  //   non-volatile const object with a preceding initialization, initialized
174  //   with a constant expression  [Note: a string literal (2.14.5 [lex.string])
175  //   corresponds to an array of such objects. -end note], or
176  volatile const int vi = 1; // expected-note {{here}}
177  const int ci = 1;
178  volatile const int &vrci = ci;
179  static_assert(vi, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type 'const volatile int'}}
180  static_assert(const_cast<int&>(vi), ""); // expected-error {{constant expression}} expected-note {{read of volatile object 'vi'}}
181  static_assert(vrci, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
182
183  // - a non-volatile glvalue of literal type that refers to a non-volatile
184  //   object defined with constexpr, or that refers to a sub-object of such an
185  //   object, or
186  struct S {
187    constexpr S(int=0) : i(1), v(1) {}
188    constexpr S(const S &s) : i(2), v(2) {}
189    int i;
190    volatile int v;
191  };
192  constexpr S s;
193  constexpr volatile S vs; // expected-note {{here}}
194  constexpr const volatile S &vrs = s;
195  static_assert(s.i, "");
196  static_assert(s.v, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
197  static_assert(vs.i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
198  static_assert(const_cast<int&>(vs.i), ""); // expected-error {{constant expression}} expected-note {{read of volatile object 'vs'}}
199  static_assert(vrs.i, ""); // expected-error {{constant expression}} expected-note {{read of volatile-qualified type}}
200
201  // - a non-volatile glvalue of literal type that refers to a non-volatile
202  //   temporary object whose lifetime has not ended, initialized with a
203  //   constant expression;
204  constexpr volatile S f() { return S(); }
205  static_assert(f().i, ""); // ok! there's no lvalue-to-rvalue conversion here!
206  static_assert(((volatile const S&&)(S)0).i, ""); // expected-error {{constant expression}} expected-note {{subexpression}}
207}
208
209// FIXME:
210//
211// DR1312: The proposed wording for this defect has issues, so we ignore this
212// bullet and instead prohibit casts from pointers to cv void (see core-20842
213// and core-20845).
214//
215// - an lvalue-to-rvalue conversion (4.1 [conv.lval]) that is applied to a
216// glvalue of type cv1 T that refers to an object of type cv2 U, where T and U
217// are neither the same type nor similar types (4.4 [conv.qual]);
218
219// FIXME:
220// - an lvalue-to-rvalue conversion (4.1) that is applied to a glvalue that
221// refers to a non-active member of a union or a subobject thereof;
222
223// - an id-expression that refers to a variable or data member of reference type
224//   unless the reference has a preceding initialization, initialized with a
225//   constant expression;
226namespace References {
227  const int a = 2;
228  int &b = *const_cast<int*>(&a);
229  int c = 10; // expected-note 2 {{here}}
230  int &d = c;
231  constexpr int e = 42;
232  int &f = const_cast<int&>(e);
233  extern int &g;
234  constexpr int &h(); // expected-note 2{{here}}
235  int &i = h(); // expected-note {{here}} expected-note {{undefined function 'h' cannot be used in a constant expression}}
236  constexpr int &j() { return b; }
237  int &k = j();
238
239  struct S {
240    int A : a;
241    int B : b;
242    int C : c; // expected-error {{constant expression}} expected-note {{read of non-const variable 'c'}}
243    int D : d; // expected-error {{constant expression}} expected-note {{read of non-const variable 'c'}}
244    int D2 : &d - &c + 1;
245    int E : e / 2;
246    int F : f - 11;
247    int G : g; // expected-error {{constant expression}}
248    int H : h(); // expected-error {{constant expression}} expected-note {{undefined function 'h'}}
249    int I : i; // expected-error {{constant expression}} expected-note {{initializer of 'i' is not a constant expression}}
250    int J : j();
251    int K : k;
252  };
253}
254
255// - a dynamic_cast (5.2.7);
256namespace DynamicCast {
257  struct S { int n; };
258  constexpr S s { 16 };
259  struct T {
260    int n : dynamic_cast<const S*>(&s)->n; // expected-warning {{constant expression}} expected-note {{dynamic_cast}}
261  };
262}
263
264// - a reinterpret_cast (5.2.10);
265namespace ReinterpretCast {
266  struct S { int n; };
267  constexpr S s { 16 };
268  struct T {
269    int n : reinterpret_cast<const S*>(&s)->n; // expected-warning {{constant expression}} expected-note {{reinterpret_cast}}
270  };
271  struct U {
272    int m : (long)(S*)6; // expected-warning {{constant expression}} expected-note {{reinterpret_cast}}
273  };
274}
275
276// - a pseudo-destructor call (5.2.4);
277namespace PseudoDtor {
278  int k;
279  typedef int I;
280  struct T {
281    int n : (k.~I(), 0); // expected-error {{constant expression}} expected-note{{subexpression}}
282  };
283}
284
285// - increment or decrement operations (5.2.6, 5.3.2);
286namespace IncDec {
287  int k = 2;
288  struct T {
289    int n : ++k; // expected-error {{constant expression}}
290    int m : --k; // expected-error {{constant expression}}
291  };
292}
293
294// - a typeid expression (5.2.8) whose operand is of a polymorphic class type;
295namespace std {
296  struct type_info {
297    virtual ~type_info();
298    const char *name;
299  };
300}
301namespace TypeId {
302  struct S { virtual void f(); };
303  constexpr S *p = 0;
304  constexpr const std::type_info &ti1 = typeid(*p); // expected-error {{must be initialized by a constant expression}} expected-note {{typeid applied to expression of polymorphic type 'TypeId::S'}}
305
306  struct T {} t;
307  constexpr const std::type_info &ti2 = typeid(t);
308}
309
310// - a new-expression (5.3.4);
311// - a delete-expression (5.3.5);
312namespace NewDelete {
313  int *p = 0;
314  struct T {
315    int n : *new int(4); // expected-error {{constant expression}} expected-note {{subexpression}}
316    int m : (delete p, 2); // expected-error {{constant expression}} expected-note {{subexpression}}
317  };
318}
319
320// - a relational (5.9) or equality (5.10) operator where the result is
321//   unspecified;
322namespace UnspecifiedRelations {
323  int a, b;
324  constexpr int *p = &a, *q = &b;
325  // C++11 [expr.rel]p2: If two pointers p and q of the same type point to
326  // different objects that are not members of the same array or to different
327  // functions, or if only one of them is null, the results of p<q, p>q, p<=q,
328  // and p>=q are unspecified.
329  constexpr bool u1 = p < q; // expected-error {{constant expression}}
330  constexpr bool u2 = p > q; // expected-error {{constant expression}}
331  constexpr bool u3 = p <= q; // expected-error {{constant expression}}
332  constexpr bool u4 = p >= q; // expected-error {{constant expression}}
333  constexpr bool u5 = p < 0; // expected-error {{constant expression}}
334  constexpr bool u6 = p <= 0; // expected-error {{constant expression}}
335  constexpr bool u7 = p > 0; // expected-error {{constant expression}}
336  constexpr bool u8 = p >= 0; // expected-error {{constant expression}}
337  constexpr bool u9 = 0 < q; // expected-error {{constant expression}}
338  constexpr bool u10 = 0 <= q; // expected-error {{constant expression}}
339  constexpr bool u11 = 0 > q; // expected-error {{constant expression}}
340  constexpr bool u12 = 0 >= q; // expected-error {{constant expression}}
341  void f(), g();
342
343  constexpr void (*pf)() = &f, (*pg)() = &g;
344  constexpr bool u13 = pf < pg; // expected-error {{constant expression}}
345  constexpr bool u14 = pf == pg;
346
347  // FIXME:
348  // If two pointers point to non-static data members of the same object with
349  // different access control, the result is unspecified.
350
351  // FIXME:
352  // [expr.rel]p3: Pointers to void can be compared [...] if both pointers
353  // represent the same address or are both the null pointer [...]; otherwise
354  // the result is unspecified.
355
356  // FIXME: Implement comparisons of pointers to members.
357  // [expr.eq]p2: If either is a pointer to a virtual member function and
358  // neither is null, the result is unspecified.
359}
360
361// - an assignment or a compound assignment (5.17); or
362namespace Assignment {
363  int k;
364  struct T {
365    int n : (k = 9); // expected-error {{constant expression}}
366    int m : (k *= 2); // expected-error {{constant expression}}
367  };
368
369  struct Literal {
370    constexpr Literal(const char *name) : name(name) {}
371    const char *name;
372  };
373  struct Expr {
374    constexpr Expr(Literal l) : IsLiteral(true), l(l) {}
375    bool IsLiteral;
376    union {
377      Literal l;
378      // ...
379    };
380  };
381  struct MulEq {
382    constexpr MulEq(Expr a, Expr b) : LHS(a), RHS(b) {}
383    Expr LHS;
384    Expr RHS;
385  };
386  constexpr MulEq operator*=(Expr a, Expr b) { return MulEq(a, b); }
387  Literal a("a");
388  Literal b("b");
389  MulEq c = a *= b; // ok
390}
391
392// - a throw-expression (15.1)
393namespace Throw {
394  struct S {
395    int n : (throw "hello", 10); // expected-error {{constant expression}} expected-note {{subexpression}}
396  };
397}
398
399// PR9999
400template<bool v>
401class bitWidthHolding {
402public:
403  static const
404  unsigned int width = (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::width + 1);
405};
406
407static const int width=bitWidthHolding<255>::width;
408
409template<bool b>
410struct always_false {
411  static const bool value = false;
412};
413
414template<bool b>
415struct and_or {
416  static const bool and_value = b && and_or<always_false<b>::value>::and_value;
417  static const bool or_value = !b || and_or<always_false<b>::value>::or_value;
418};
419
420static const bool and_value = and_or<true>::and_value;
421static const bool or_value = and_or<true>::or_value;
422