Lines Matching refs:constant

6 static_assert(++x, "test"); // expected-error {{not an integral constant expression}}
104 case __builtin_constant_p(true) ? (__SIZE_TYPE__)&x : 0:; // expected-error {{constant}}
112 constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'Recurse2' is not a constant expression}}
117 constexpr int RecurseC = RecurseB; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'RecurseB' is not a constant expression}}
153 static_assert(F(4, k) == 3, ""); // expected-error {{constant expression}} expected-note {{read of non-const variable 'k'}}
205 constexpr int a = MaybeReturnJunk(true, 0); // expected-error {{constant expression}} expected-note {{read of variable whose lifetime has ended}}
216 constexpr int n3 = InternalReturnJunk(0); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'InternalReturnJunk(0)'}}
256 constexpr int Invalid = Apply(Select(0), 0); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'Apply(0, 0)'}}
267 constexpr bool g3 = &x <= &y; // expected-error {{must be initialized by a constant expression}}
268 constexpr bool g4 = &x >= &y; // expected-error {{must be initialized by a constant expression}}
269 constexpr bool g5 = &x < &y; // expected-error {{must be initialized by a constant expression}}
270 constexpr bool g6 = &x > &y; // expected-error {{must be initialized by a constant expression}}
282 constexpr bool n3 = 0 <= &y; // expected-error {{must be initialized by a constant expression}}
283 constexpr bool n4 = 0 >= &y; // expected-error {{must be initialized by a constant expression}}
284 constexpr bool n5 = 0 < &y; // expected-error {{must be initialized by a constant expression}}
285 constexpr bool n6 = 0 > &y; // expected-error {{must be initialized by a constant expression}}
289 constexpr bool n9 = &x <= 0; // expected-error {{must be initialized by a constant expression}}
290 constexpr bool n10 = &x >= 0; // expected-error {{must be initialized by a constant expression}}
291 constexpr bool n11 = &x < 0; // expected-error {{must be initialized by a constant expression}}
292 constexpr bool n12 = &x > 0; // expected-error {{must be initialized by a constant expression}}
302 constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr); // expected-error {{constant expression}} expected-note {{dynamic_cast}}
307 expected-warning {{not an integral constant expression}} \
308 expected-note {{dynamic_cast is not allowed in a constant expression}}
310 expected-warning {{not an integral constant expression}} \
311 expected-note {{reinterpret_cast is not allowed in a constant expression}}
313 expected-warning {{not an integral constant expression}} \
314 expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
316 expected-warning {{not an integral constant expression}} \
317 expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
319 expected-warning {{not an integral constant expression}} \
320 expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
322 expected-warning {{not an integral constant expression}} \
323 expected-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
325 expected-warning {{not an integral constant expression}} \
326 expected-note {{cast from 'void *' is not allowed in a constant expression}}
330 constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}}
331 constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}} expected-warning {{unspecified}}
354 static_assert(&b1.a1.r != &b1.a2.r, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
358 static_assert(&b1.a1 != &b2.a1, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
360 constexpr thread_local B b3 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
363 constexpr thread_local B b2 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
364 constexpr B b3 { { 1 }, { 2 } }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
371 constexpr B b5 = B{ {0}, {0} }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
374 // Proposed DR: for a reference constant expression to refer to a static
376 // by a constant expression (a core constant expression is not enough).
380 constexpr B b = { A(A{0}) }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
410 constexpr char c2 = "nasty index"[12]; // expected-error {{must be initialized by a constant expression}} expected-warning {{is past the end}} expected-note {{read of dereferenced one-past-the-end pointer}}
411 constexpr char c3 = "negative index"[-1]; // expected-error {{must be initialized by a constant expression}} expected-warning {{is before the beginning}} expected-note {{cannot refer to element -1 of array of 15 elements}}
412 constexpr char c4 = ((char*)(int*)"no reinterpret_casts allowed")[14]; // expected-error {{must be initialized by a constant expression}} expected-note {{cast that performs the conversions of a reinterpret_cast}}
435 int n : "foo"[4]; // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}}
450 static_assert(t.c[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
474 static_assert(f[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
509 expected-error {{constant expression}} \
514 constexpr int xs5 = p[2]; // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
515 constexpr int xs6 = p[3]; // expected-error {{constant expression}} expected-note {{cannot refer to element 6}}
517 constexpr int xs_1 = p[-4]; // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
522 static_assert(zs[0][0][0][2] == 3, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
525 static_assert(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][-1] + 1) == 11, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element -1 of array of 2 elements in a constant expression}}
527 constexpr int err_zs_1_2_0_0 = zs[1][2][0][0]; // expected-error {{constant expression}} expected-note {{cannot access array element of pointer past the end}}
533 expected-error {{static_assert expression is not an integral constant expression}} \
623 // This is a constant expression if we elide the copy constructor call, and
624 // is not a constant expression if we don't! But we do, so it is.
652 static_assert(g.t.u1.a == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'a' of union with active member 'b'}}
655 static_assert(g.t.u2.d == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'd' of union with active member 'c'}}
699 static_assert(agg1.arr[-1] == 0, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
702 static_assert(agg1.arr[5] == 0, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end}}
766 constexpr Base2 &fail = (Base2&)bot1; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base2'}}
767 constexpr Base &fail2 = (Base&)*pb2; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base'}}
771 constexpr Base2 *pfail = (Base2*)pb1; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base2'}}
772 constexpr Base *pfail2 = (Base*)&bot2; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'const Class::Derived' to type 'Class::Base'}}
779 // Core issue 903: we do not perform constant evaluation when checking for a
832 constexpr int x = f(); // expected-error {{must be initialized by a constant}}
834 constexpr int y = this->f(); // expected-error {{must be initialized by a constant}}
864 static_assert(S().f(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->f()'}}
865 static_assert(S().g(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->g()'}}
882 constexpr int k = NonLiteral().f(); // expected-error {{constant expression}} expected-note {{non-literal type 'Temporaries::NonLiteral'}}
895 static_assert(u[0].b, ""); // expected-error {{constant expression}} expected-note {{read of member 'b' of union with active member 'a'}}
897 static_assert((&u[1].b)[1] == 2, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
898 static_assert(*(&(u[1].b) + 1 + 1) == 3, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element 2 of non-array object}}
911 static_assert(y.b == 42, ""); // expected-error {{constant expression}} expected-note {{'b' of union with active member 'a'}}
978 static_assert(pg == pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
979 static_assert(pf != pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
993 constexpr int *pbad = &(t17.*deepm); // expected-error {{constant expression}}
1000 constexpr T<23> *p17_23 = (T<23>*)p17_13; // expected-error {{constant expression}} expected-note {{cannot cast object of dynamic type 'T<17>' to type 'T<23>'}}
1003 constexpr int *pbad2 = &(p17_13->*(int(T<9>::*))deepm); // expected-error {{constant expression}}
1042 constexpr int pb4n = pb4->n; // expected-error {{constant expression}} expected-note {{cannot access field of pointer past the end}}
1043 constexpr Base *err_pb5 = pb3 + 2; // expected-error {{constant expression}} expected-note {{cannot refer to element 2}} expected-note {{here}}
1044 constexpr int err_pb5n = err_pb5->n; // expected-error {{constant expression}} expected-note {{initializer of 'err_pb5' is not a constant expression}}
1045 constexpr Base *err_pb2 = pb3 - 1; // expected-error {{constant expression}} expected-note {{cannot refer to element -1}} expected-note {{here}}
1046 constexpr int err_pb2n = err_pb2->n; // expected-error {{constant expression}} expected-note {{initializer of 'err_pb2'}}
1050 constexpr Derived *err_pd4 = (Derived*)pb4; // expected-error {{constant expression}} expected-note {{cannot access derived class of pointer past the end}}
1060 constexpr int err_pd10n = pd10->n; // expected-error {{constant expression}} expected-note {{cannot access base class of pointer past the end}}
1062 constexpr int err_pdminus1n = pd10[-11].n; // expected-error {{constant expression}} expected-note {{cannot refer to element -1 of}}
1134 static_assert(B().x == 3, ""); // expected-error {{constant expression}} expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
1136 constexpr bool f(int k) { // expected-error {{constexpr function never produces a constant expression}}
1137 return B().x == k; // expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
1153 constexpr int m1 = n1; // expected-error {{constant expression}} expected-note {{read of volatile-qualified type 'const volatile int'}}
1154 constexpr int m2 = n2; // expected-error {{constant expression}} expected-note {{read of volatile-qualified type 'const volatile int'}}
1155 constexpr int m1b = const_cast<const int&>(n1); // expected-error {{constant expression}} expected-note {{read of volatile object 'n1'}}
1156 constexpr int m2b = const_cast<const int&>(n2); // expected-error {{constant expression}} expected-note {{read of volatile object 'n2'}}
1165 return const_cast<int&>(r); // expected-note {{read of volatile temporary is not allowed in a constant expression}}
1168 int j : f(0); // expected-error {{constant expression}} expected-note {{in call to 'f(0)'}}
1169 int k : g(0); // expected-error {{constant expression}} expected-note {{temporary created here}} expected-note {{in call to 'g(0)'}}
1170 int l : n3; // expected-error {{constant expression}} expected-note {{read of non-const variable}}
1171 int m : t.n; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable}}
1202 static_assert(t2p[-1] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element -1 of array of 2 elements}}
1205 static_assert(t2p[2] == 0.0, ""); // expected-error {{constant expr}} expected-note {{one-past-the-end pointer}}
1206 static_assert(t2p[3] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element 3 of array of 2 elements}}
1208 constexpr float pr = __real *p; // expected-error {{constant expr}} expected-note {{cannot access real component of null}}
1209 constexpr float pi = __imag *p; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of null}}
1211 constexpr double qr = __real *q; // expected-error {{constant expr}} expected-note {{cannot access real component of pointer past the end}}
1212 constexpr double qi = __imag *q; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of pointer past the end}}
1219 // _Atomic(T) is exactly like T for the purposes of constant expression
1258 // useless note and instead just point to the non-constant subexpression.
1261 en = n, // expected-error {{not a constant expression}}
1263 n // expected-error {{not a constant expression}}
1265 eq = reinterpret_cast<int>((int*)0) // expected-error {{not a constant expression}} expected-note {{reinterpret_cast}}
1296 static_assert(s1.c == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1299 static_assert(s1.f == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1301 static_assert(s2.a == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1302 static_assert(s2.b == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1305 static_assert(s2.e == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1309 // DR1405: don't allow reading mutable members in constant expressions.
1314 constexpr int mmn = mm.n; // expected-error {{constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
1316 constexpr int mmn2 = mm.n; // expected-error {{constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
1323 return Id<m.n>().k; // expected-error {{not a constant expression}} expected-note {{read of mutable member 'n' is not allowed in a constant expression}}
1330 constexpr int k = c[1].b.a.n; // expected-error {{constant expression}} expected-note {{mutable}}
1335 constexpr D d2 = d1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
1344 constexpr E e2 = e1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
1365 constexpr G g2 = g1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
1373 constexpr H h2 = h1; // expected-error {{constant}} expected-note {{mutable}} expected-note {{in call}}
1378 // This macro forces its argument to be constant-folded, even if it's not
1379 // otherwise a constant expression.
1382 constexpr int n = (int)(char*)123; // expected-error {{constant expression}} expected-note {{reinterpret_cast}}
1411 constexpr const int l = k; // expected-error {{constant expression}} expected-note {{read of temporary}}
1416 constexpr const int &i = 1; // expected-error {{constant expression}} expected-note 2{{temporary}}
1450 sizeof(arr) // expected-error {{constant expression}}
1460 // pointer to it. This is OK: we're not required to treat this as a constant
1462 constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expression}} expected-note 2{{temporary}}
1580 constexpr int *p = &n; // expected-error{{constexpr variable 'p' must be initialized by a constant expression}}
1583 constexpr int *q = f(); // expected-error{{constexpr variable 'q' must be initialized by a constant expression}}
1604 static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \
1615 constexpr auto &y = typeid(g()); // expected-error{{constant expression}} \
1616 // expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} \
1636 // this would be a constant expression. For now, we generate a move
1664 // expected-error@-2 {{constexpr variable 'p' must be initialized by a constant expression}}
1665 // expected-note@-3 {{pointer to temporary is not a constant expression}}
1674 constexpr int k = error(); // expected-error {{must be initialized by a constant expression}}
1734 constexpr int h() { // expected-error {{never produces a constant}}
1758 static_assert(p->f() == sizeof(X<S1>), ""); // expected-error {{constant expression}} expected-note {{virtual function call}}
1783 constexpr int &n = n; // expected-error {{constant expression}} expected-note {{use of reference outside its lifetime}} expected-warning {{not yet bound to a value}}
1784 constexpr int m = m; // expected-error {{constant expression}} expected-note {{read of object outside its lifetime}}
1796 constexpr int k2 = S(0).t; // expected-error {{constant expression}} expected-note {{in call}}
1839 // expected-error@-1 {{constexpr variable 'k' must be initialized by a constant expression}}
1843 constexpr int f() { // expected-error {{never produces a constant expression}}
1853 X<A().k>::n; // expected-error {{not a constant expression}} expected-note {{implicit default constructor for 'BadDefaultInit::A' first required here}}
1868 // If we see something non-constant but foldable followed by something
1869 // non-constant and not foldable, we want the first diagnostic, not the
1871 constexpr int f(int n) { // expected-error {{never produces a constant expression}}
1878 constexpr int n = // expected-error {{must be initialized by a constant expression}}
1923 constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
1924 constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
1925 constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
1927 constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
1928 constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
1929 constexpr int under3 = __builtin_strlen(c - 1); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
1933 constexpr int bad = __builtin_strlen(d); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
1947 static_assert(&a + 1 != &b, ""); // expected-error {{constant expression}}
1959 constexpr E2 e2b(e2); // expected-error {{constant expression}} expected-note{{read of non-const}} expected-note {{in call}}
1966 static_assert(&start != &end, ""); // expected-error {{constant expression}}
1980 constexpr int Var = Fun(); // expected-error {{constexpr variable 'Var' must be initialized by a constant expression}}