Lines Matching defs:static_assert

6 static_assert(++x, "test"); // expected-error {{not an integral constant expression}}
7 static_assert(false, "test"); // expected-error {{test}}
41 static_assert((void*)p != (void*)q, "");
42 static_assert((A*)p == (A*)q, "");
43 static_assert((Aa*)p != (Aa*)q, "");
47 static_assert((void*)&pp != (void*)&qq, "");
48 static_assert(&(A&)pp == &(A&)qq, "");
49 static_assert(&(Aa&)pp != &(Aa&)qq, "");
54 static_assert(v == w, "");
55 static_assert(v == x, "");
57 static_assert((U*)&d == p, "");
58 static_assert((U*)&d == q, "");
59 static_assert((U*)&d == v, "");
60 static_assert((U*)&d == w, "");
61 static_assert((U*)&d == x, "");
68 static_assert((X*)(Y1*)&z != (X*)(Y2*)&z, "");
85 static_assert(n9 == 123, "");
122 static_assert(wme.A == 42, "");
134 static_assert(Sum() == 0, "");
135 static_assert(Sum(1) == 1, "");
136 static_assert(Sum(1, four) == 5, "");
137 static_assert(Sum(1, eight, &twentyseven) == 36, "");
138 static_assert(Sum(1, 2, &four, eight) == 15, "");
146 static_assert(F(0) == 0, "");
147 static_assert(F(1, 0) == 1, "");
148 static_assert(F(2, "test") == 2, "");
149 static_assert(F(3, &F) == 3, "");
151 static_assert(F(4, k) == 3, ""); // expected-error {{constant expression}} expected-note {{read of non-const variable 'k'}}
157 static_assert(fib(11) == 89, "");
166 static_assert(gcd(1749237, 5628959) == 7, "");
186 static_assert(S::f(19) == 800, "");
187 static_assert(s.f(19) == 800, "");
188 static_assert(n == 800, "");
202 static_assert(MaybeReturnJunk(false, 0) == 42, ""); // ok
208 static_assert(MaybeReturnNonstaticRef(false, 0) == 42, ""); // ok
220 static_assert(GrabCallersArgument(false, 1, 2) == 1, "");
221 static_assert(GrabCallersArgument(true, 4, 8) == 8, "");
232 static_assert(f(23, &x, &y, &z) == 788, "");
237 static_assert(g(23, x, y, z) == 788, "");
252 static_assert(1 + Apply(Select(4), 5) + Apply(Select(3), 7) == 42, "");
261 static_assert(&x == &y, "false"); // expected-error {{false}}
262 static_assert(&x != &y, "");
271 static_assert(&s.x == &s.y, "false"); // expected-error {{false}}
272 static_assert(&s.x != &s.y, "");
273 static_assert(&s.x <= &s.y, "");
274 static_assert(&s.x >= &s.y, "false"); // expected-error {{false}}
275 static_assert(&s.x < &s.y, "");
276 static_assert(&s.x > &s.y, "false"); // expected-error {{false}}
278 static_assert(0 == &y, "false"); // expected-error {{false}}
279 static_assert(0 != &y, "");
285 static_assert(&x == 0, "false"); // expected-error {{false}}
286 static_assert(&x != 0, "");
292 static_assert(&x == &x, "");
293 static_assert(&x != &x, "false"); // expected-error {{false}}
294 static_assert(&x <= &x, "");
295 static_assert(&x >= &x, "");
296 static_assert(&x < &x, "false"); // expected-error {{false}}
297 static_assert(&x > &x, "false"); // expected-error {{false}}
330 static_assert(0 != "foo", "");
342 static_assert(n, "");
343 static_assert(!same(4, 4), "");
344 static_assert(same(n, n), "");
345 static_assert(sameTemporary(9), "");
351 static_assert(&b1.a1 != &b1.a2, "");
352 static_assert(&b1.a1.r != &b1.a2.r, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
355 static_assert(&b1 != &b2, "");
356 static_assert(&b1.a1 != &b2.a1, ""); // expected-error {{constant expression}} expected-note {{outside the expression that created the temporary}}
366 static_assert(&b4 != &b2, "");
400 static_assert(MangleChars("constexpr!") == 1768383, "");
401 static_assert(MangleChars(u8"constexpr!") == 1768383, "");
402 static_assert(MangleChars(L"constexpr!") == 1768383, "");
403 static_assert(MangleChars(u"constexpr!") == 1768383, "");
404 static_assert(MangleChars(U"constexpr!") == 1768383, "");
413 static_assert(*p == 's', "");
424 static_assert(*max == 'z', "");
425 static_assert(max == str + 38, "");
427 static_assert(strcmp_ce("hello world", "hello world") == 0, "");
428 static_assert(strcmp_ce("hello world", "hello clang") > 0, "");
429 static_assert(strcmp_ce("constexpr", "test") < 0, "");
430 static_assert(strcmp_ce("", " ") < 0, "");
442 static_assert(t.c[0] == 'f', "");
443 static_assert(t.c[1] == 'o', "");
444 static_assert(t.c[2] == 'o', "");
445 static_assert(t.c[3] == 0, "");
446 static_assert(t.c[4] == 0, "");
447 static_assert(t.c[5] == 0, "");
448 static_assert(t.c[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
454 static_assert(u.chars[2] == L's', "");
460 static_assert(V().c[1] == "i"[0], "");
465 static_assert(a[0] == 'f', "");
466 static_assert(b[1] == 'o', "");
467 static_assert(c[2] == 'o', "");
468 static_assert(d[0] == 'f', "");
469 static_assert(e[1] == 'o', "");
470 static_assert(f[2] == 'o', "");
471 static_assert(f[5] == 0, "");
472 static_assert(f[6] == 0, ""); // expected-error {{constant expression}} expected-note {{one-past-the-end}}
487 static_assert(sum_xs == 15, "");
501 static_assert(InnerProduct == 35, "");
505 static_assert(DiffProd == 8, "");
506 static_assert(ZipFoldR(SubMul, 3, xs+3, ys+3, 1), ""); // \
518 static_assert(zs[0][0][0][0] == 1, "");
519 static_assert(zs[1][1][1][1] == 16, "");
520 static_assert(zs[0][0][0][2] == 3, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
521 static_assert((&zs[0][0][0][2])[-1] == 2, "");
522 static_assert(**(**(zs + 1) + 1) == 11, "");
523 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}}
524 static_assert(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][2] - 2) == 11, "");
530 static_assert(fail(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][2] - 2)) == 11, ""); // \
531 expected-error {{static_assert expression is not an integral constant expression}} \
541 static_assert(SumNonzero(arr) == 6, "");
542 static_assert(CountZero(arr, arr + 40) == 36, "");
553 static_assert(ArrayRVal().elems[3].f() == 0, "");
559 static_assert(selfref[0][0][0] == 1, "");
560 static_assert(selfref[0][0][1] == 2, "");
561 static_assert(selfref[0][1][0] == 1, "");
562 static_assert(selfref[0][1][1] == 2, "");
563 static_assert(selfref[1][0][0] == 1, "");
564 static_assert(selfref[1][0][1] == 3, "");
565 static_assert(selfref[1][1][0] == 0, "");
566 static_assert(selfref[1][1][1] == 0, "");
570 static_assert(TDCArray{}[1][1].n == 0, "");
574 static_assert(NATDCArray{}[1][1].n == 0, "");
603 static_assert(fn(A(4,5)) == 9, "");
614 static_assert(D().c.n == 42, "");
624 static_assert(e2.p == &e2.p, "");
626 static_assert(e3.p == &e3.p, "");
650 static_assert(g.t.u1.a == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'a' of union with active member 'b'}}
651 static_assert(g.t.u1.b == 42, "");
652 static_assert(g.t.u2.c == 42, "");
653 static_assert(g.t.u2.d == 42, ""); // expected-error {{constant expression}} expected-note {{read of member 'd' of union with active member 'c'}}
666 static_assert(S(15, &global).b == 15, "");
671 static_assert(CheckS(S(27, &global)), "");
681 static_assert(k == 0x007a7978, "");
694 static_assert(strcmp_ce(&agg1.c, "hello") == 0, "");
695 static_assert(agg1.n == 0, "");
696 static_assert(agg1.d == 0.0, "");
697 static_assert(agg1.arr[-1] == 0, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element -1}}
698 static_assert(agg1.arr[0] == 0, "");
699 static_assert(agg1.arr[4] == 0, "");
700 static_assert(agg1.arr[5] == 0, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end}}
701 static_assert(agg1.p == nullptr, "");
704 static_assert(uc[0] == 'f', "");
705 static_assert(uc[3] == 0, "");
717 static_assert(d.a == 3, "");
744 static_assert(derived.a == 76, "");
745 static_assert(derived.b[2] == 's', "");
746 static_assert(derived.c == 76 + 'e', "");
747 static_assert(derived.q == 123, "");
748 static_assert(derived.r == 76, "");
749 static_assert(&derived.r == &derived.a, "");
751 static_assert(!(derived == base), "");
752 static_assert(derived == base2, "");
756 static_assert(&bot1 != &bot2, "");
760 static_assert(&pb1 != &pb2, "");
761 static_assert(pb1 == &bot1, "");
762 static_assert(pb2 == &bot2, "");
767 static_assert(&ok2 == &derived, "");
772 static_assert(pok2 == &derived, "");
773 static_assert(&ok2 == pok2, "");
774 static_assert((Base2*)(Derived*)(Base*)pb1 == pok2, "");
775 static_assert((Derived*)(Base*)pb1 == (Derived*)pok2, "");
781 static_assert((Bottom*)nullB == 0, "");
782 static_assert((Derived*)nullB == 0, "");
783 static_assert((void*)(Bottom*)nullB == (void*)(Derived*)nullB, "");
791 static_assert(nullB1 == (1 - 1), ""); // expected-error {{comparison between pointer and integer}}
812 static_assert(S(5) == 11, "");
813 static_assert(check(S(5), 11), "");
820 static_assert(X() == 0, "");
835 static_assert(z == 0, "");
862 static_assert(S().f(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->f()'}}
863 static_assert(S().g(), ""); // expected-error {{constant expression}} expected-note {{in call to '&Temporaries::S()->g()'}}
864 static_assert(T(3).f() == 3, "");
865 static_assert(T(4).g() == 4, "");
871 static_assert(f(T(5)) == 5, "");
874 static_assert(b(0), "");
892 static_assert(u[0].a == 0, "");
893 static_assert(u[0].b, ""); // expected-error {{constant expression}} expected-note {{read of member 'b' of union with active member 'a'}}
894 static_assert(u[1].b == 1, "");
895 static_assert((&u[1].b)[1] == 2, ""); // expected-error {{constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
896 static_assert(*(&(u[1].b) + 1 + 1) == 3, ""); // expected-error {{constant expression}} expected-note {{cannot refer to element 2 of non-array object}}
897 static_assert((&(u[1]) + 1 + 1)->b == 3, "");
900 static_assert(v.a == 0, "");
908 static_assert(y.a == 42, "");
909 static_assert(y.b == 42, ""); // expected-error {{constant expression}} expected-note {{'b' of union with active member 'a'}}
920 static_assert(A(5).*&A::n == 5, "");
921 static_assert((&a)->*&A::n == 7, "");
922 static_assert((A(8).*&A::f)() == 11, "");
923 static_assert(((&a)->*&A::f)() == 10, "");
931 static_assert(B(4, 11).*&A::n == 4, "");
932 static_assert(B(4, 11).*&B::m == 11, "");
933 static_assert(B(4, 11).*(int(A::*))&B::m == 11, "");
934 static_assert((&b)->*&A::n == 9, "");
935 static_assert((&b)->*&B::m == 13, "");
936 static_assert((&b)->*(int(A::*))&B::m == 13, "");
937 static_assert((B(4, 11).*&A::f)() == 7, "");
938 static_assert((B(4, 11).*&B::g)() == 16, "");
939 static_assert((B(4, 11).*(int(A::*)()const)&B::g)() == 16, "");
940 static_assert(((&b)->*&A::f)() == 12, "");
941 static_assert(((&b)->*&B::g)() == 23, "");
942 static_assert(((&b)->*(int(A::*)()const)&B::g)() == 23, "");
964 static_assert((s.*&S::f)() == 2, "");
965 static_assert((s.*s.pf)() == 2, "");
967 static_assert(pf == &S::f, "");
968 static_assert(pf == s.*&S::pf, "");
969 static_assert(pm == &S::m, "");
970 static_assert(pm != pn, "");
971 static_assert(s.pn != pn, "");
972 static_assert(s.pn == pm, "");
973 static_assert(pg != nullptr, "");
974 static_assert(pf != nullptr, "");
975 static_assert((int S::*)nullptr == nullptr, "");
976 static_assert(pg == pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
977 static_assert(pf != pg, ""); // expected-error {{constant expression}} expected-note {{comparison of pointer to virtual member function 'g' has unspecified value}}
987 static_assert(&(t17.*deepn) == &t17.n, "");
988 static_assert(deepn == &T<2>::n, "");
992 static_assert(&(t30.*deepm) == &t30.m, "");
993 static_assert(deepm == &T<50>::m, "");
994 static_assert(deepm != deepn, "");
999 static_assert(&(p17_5->*(int(T<3>::*))deepn) == &t17.n, "");
1000 static_assert(&(p17_13->*deepn) == &t17.n, "");
1006 static_assert(&(p30_5->*(int(T<3>::*))deepn) == &t30.n, "");
1007 static_assert(&(p30_13->*deepn) == &t30.n, "");
1008 static_assert(&(p30_23->*deepn) == &t30.n, "");
1009 static_assert(&(p30_5->*(int(T<2>::*))deepm) == &t30.m, "");
1010 static_assert(&(((T<17>*)p30_13)->*deepm) == &t30.m, "");
1011 static_assert(&(p30_23->*deepm) == &t30.m, "");
1016 static_assert(&Mid<0>::n == &Mid<1>::n, "");
1017 static_assert((int Derived::*)(int Mid<0>::*)&Mid<0>::n !=
1019 static_assert(&Mid<0>::n == (int Mid<0>::*)&Base::n, "");
1036 static_assert(pb3 == pd3, "");
1054 static_assert(pd6 == &a[6], "");
1065 static_assert((pb9->*pfb)() == &a[9].n, "");
1097 static_assert(complex(1,0).real() == 1, "");
1098 static_assert(complex(1,0).imag() == 0, "");
1099 static_assert(((complex)1).imag() == 0, "");
1100 static_assert(k.real() == 34, "");
1101 static_assert(k.imag() == 12, "");
1102 static_assert(k - 34 == 12*i, "");
1103 static_assert((complex)1 == complex(1), "");
1104 static_assert((complex)1 != complex(0, 1), "");
1105 static_assert(complex(1) == complex(1), "");
1106 static_assert(complex(1) != complex(0, 1), "");
1108 static_assert(makeComplex(1,0) == complex(1), "");
1109 static_assert(makeComplex(1,0) != complex(0, 1), "");
1117 static_assert((complex_wrap)1 == complex(1), "");
1118 static_assert((complex)1 != complex_wrap(0, 1), "");
1119 static_assert(complex(1) == complex_wrap(1), "");
1120 static_assert(complex_wrap(1) != complex(0, 1), "");
1124 static_assert(makeComplexWrap(1,0) == complex(1), "");
1125 static_assert(makeComplexWrap(1,0) != complex(0, 1), "");
1132 static_assert(B().x == 3, ""); // expected-error {{constant expression}} expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
1196 static_assert(&t2r + 1 == &t2i, "");
1197 static_assert(t2r == 1.0, "");
1198 static_assert(t2i == 2.0, "");
1200 static_assert(t2p[-1] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element -1 of array of 2 elements}}
1201 static_assert(t2p[0] == 1.0, "");
1202 static_assert(t2p[1] == 2.0, "");
1203 static_assert(t2p[2] == 0.0, ""); // expected-error {{constant expr}} expected-note {{one-past-the-end pointer}}
1204 static_assert(t2p[3] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element 3 of array of 2 elements}}
1212 static_assert(__real test6 == 5, "");
1213 static_assert(__imag test6 == 6, "");
1214 static_assert(&__imag test6 == &__real test6 + 1, "");
1229 static_assert(d1 == 0.5, "");
1230 static_assert(d3 == 3.0, "");
1238 static_assert(testVar.value == -1, "");
1292 static_assert(s1.a == 1, "");
1293 static_assert(s1.b == 2, "");
1294 static_assert(s1.c == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1295 static_assert(s1.d == 3, "");
1296 static_assert(s1.e == 4, "");
1297 static_assert(s1.f == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1299 static_assert(s2.a == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1300 static_assert(s2.b == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1301 static_assert(s2.c == 5, "");
1302 static_assert(s2.d == 6, "");
1303 static_assert(s2.e == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}}
1304 static_assert(s2.f == 7, "");
1339 static_assert(m == 123, "");
1360 static_assert(j == 1, "");
1383 static_assert(LastNonzero(begin(arr1), end(arr1)) == 4, "");
1386 static_assert(LastNonzero(begin(arr2), end(arr2)) == 5, "");
1397 static_assert(LastNonzero(begin(arr3), end(arr3)) == 2, "");
1458 static_assert(!__is_literal_type(Q), "");
1459 static_assert(!__is_literal_type(R), "");
1460 static_assert(!__is_literal_type(S), "");
1461 static_assert(!__is_literal_type(T), "");
1462 static_assert(!__is_literal_type(U), "");
1497 static_assert(S{}.t == 0, "");
1507 static_assert(x[0].m == 4, "");
1508 static_assert(x[1].m == 5, "");
1509 static_assert(x[2].m == 6, "");
1526 static_assert(f(a).v == 4, "");
1557 static_assert(get(arr, 1) == 1, "");
1558 static_assert(get(arr, 4) == 4, "");
1559 static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \
1601 static_assert(a[0].p == &a[0].p, "");
1602 static_assert(a[9].p == &a[9].p, "");
1603 static_assert(a[0].p != &a[9].p, "");
1604 static_assert(a[9].p != &a[0].p, "");
1607 static_assert(b[0].p == &b[0].p, "");
1608 static_assert(b[9].p == &b[9].p, "");
1609 static_assert(b[0].p != &b[9].p, "");
1610 static_assert(b[9].p != &b[0].p, "");
1669 static_assert(sum({1, 2, 3, 4, 5}) == 15, "");
1675 static_assert(({ const int x = 5; x * 3; }) == 15, ""); // expected-warning {{extension}}
1684 static_assert(g(123) == 15129, "");
1709 static_assert(p->f() == sizeof(X<S1>), ""); // expected-error {{constant expression}} expected-note {{virtual function call}}
1714 static_assert(q->f() == sizeof(S2), "");
1761 static_assert(a.b == 0 && a.u == 1 && a.n == -1 && a.b2 == 0 &&
1769 static_assert(B(3).n == 3, "");
1770 static_assert(B(4).n == -4, "");
1771 static_assert(B(7).n == -1, "");
1772 static_assert(B(8).n == 0, "");
1773 static_assert(B(-1).n == -1, "");
1774 static_assert(B(-8889).n == -1, "");
1783 static_assert(X::f(3) == -1, "3 should truncate to -1");
1853 static_assert(__builtin_strlen("foo") == 3, "");
1854 static_assert(__builtin_strlen("foo\0quux") == 3, "");
1855 static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
1869 static_assert(check(a), "");
1870 static_assert(check(b), "");
1871 static_assert(check(c), "");