• Home
  • Raw
  • Download

Lines Matching refs:constexpr

13 template<typename T> constexpr T id(const T &t) { return t; }  in id()
14 template<typename T> constexpr T min(const T &a, const T &b) { in min()
17 template<typename T> constexpr T max(const T &a, const T &b) { in max()
20 template<typename T, size_t N> constexpr T *begin(T (&xs)[N]) { return xs; } in begin()
21 template<typename T, size_t N> constexpr T *end(T (&xs)[N]) { return xs + N; } in end()
24 constexpr int zero() { return 0; } in zero()
38 constexpr B *p = &d;
39 constexpr C *q = &d;
45 constexpr B &pp = d;
46 constexpr C &qq = d;
51 constexpr V *v = p;
52 constexpr V *w = q;
53 constexpr V *x = (A*)p;
73 constexpr int n1 = 0;
74 constexpr int n2 = const_cast<int&>(n1);
75 constexpr int *n3 = const_cast<int*>(&n1);
76 constexpr int n4 = *const_cast<int*>(&n1);
77 constexpr const int * const *n5 = const_cast<const int* const*>(&n3);
78 constexpr int **n6 = const_cast<int**>(&n3);
79 constexpr int n7 = **n5;
80 constexpr int n8 = **n6;
105 constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expressio…
110 constexpr int RecurseC = RecurseB; // expected-error {{must be initialized by a constant expression…
123 constexpr int Sum(int a = 0, const int &b = 0, const int *c = &z, char d = 0) { in Sum()
127 constexpr int eight = 8;
128 constexpr const int twentyseven = 27;
140 constexpr int F(int a, ...) { return a; } in F()
151 constexpr int fib(int n) { return n > 1 ? fib(n-1) + fib(n-2) : n; } in fib()
154 constexpr int gcd_inner(int a, int b) { in gcd_inner()
157 constexpr int gcd(int a, int b) { in gcd()
167 constexpr int f() { return 1; } in f()
176 static constexpr int k = 42;
177 static constexpr int f(int n) { return n * k + 2; } in f()
180 constexpr int n = s.f(19);
185 constexpr int (*sf1)(int) = &S::f;
186 constexpr int (*sf2)(int) = &s.f;
187 constexpr const int *sk = &s.k;
193 constexpr const int &ObscureTheTruth(const int &a) { return a; } in ObscureTheTruth()
194 constexpr const int &MaybeReturnJunk(bool b, const int a) { // expected-note 2{{declared here}} in MaybeReturnJunk()
198constexpr int a = MaybeReturnJunk(true, 0); // expected-error {{constant expression}} expected-not…
200 constexpr const int MaybeReturnNonstaticRef(bool b, const int a) { in MaybeReturnNonstaticRef()
204 constexpr int b = MaybeReturnNonstaticRef(true, 0); // ok
206 constexpr int InternalReturnJunk(int n) { in InternalReturnJunk()
209constexpr int n3 = InternalReturnJunk(0); // expected-error {{must be initialized by a constant ex…
211 constexpr int LToR(int &n) { return n; } in LToR()
212 constexpr int GrabCallersArgument(bool which, int a, int b) { in GrabCallersArgument()
222 constexpr int f(int n, const int *a, const int *b, const int *c) { in f()
229 constexpr int g(int n, int a, int b, int c) { in g()
238 constexpr int Double(int n) { return 2 * n; } in Double()
239 constexpr int Triple(int n) { return 3 * n; } in Triple()
240 constexpr int Twice(int (*F)(int), int n) { return F(F(n)); } in Twice()
241 constexpr int Quadruple(int n) { return Twice(Double, n); } in Quadruple()
242 constexpr auto Select(int n) -> int (*)(int) { in Select()
245 constexpr int Apply(int (*F)(int), int n) { return F(n); } // expected-note {{subexpression}} in Apply()
249constexpr int Invalid = Apply(Select(0), 0); // expected-error {{must be initialized by a constant…
258 constexpr bool g1 = &x == &y;
259 constexpr bool g2 = &x != &y;
260 constexpr bool g3 = &x <= &y; // expected-error {{must be initialized by a constant expression}}
261 constexpr bool g4 = &x >= &y; // expected-error {{must be initialized by a constant expression}}
262 constexpr bool g5 = &x < &y; // expected-error {{must be initialized by a constant expression}}
263 constexpr bool g6 = &x > &y; // expected-error {{must be initialized by a constant expression}}
275 constexpr bool n3 = 0 <= &y; // expected-error {{must be initialized by a constant expression}}
276 constexpr bool n4 = 0 >= &y; // expected-error {{must be initialized by a constant expression}}
277 constexpr bool n5 = 0 < &y; // expected-error {{must be initialized by a constant expression}}
278 constexpr bool n6 = 0 > &y; // expected-error {{must be initialized by a constant expression}}
282 constexpr bool n9 = &x <= 0; // expected-error {{must be initialized by a constant expression}}
283 constexpr bool n10 = &x >= 0; // expected-error {{must be initialized by a constant expression}}
284 constexpr bool n11 = &x < 0; // expected-error {{must be initialized by a constant expression}}
285 constexpr bool n12 = &x > 0; // expected-error {{must be initialized by a constant expression}}
294 constexpr S* sptr = &s;
295 constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr); // expected-error {{constant expression}} …
323 constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be …
324 constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant e…
331 constexpr int f(const int &r) { return r; } in f()
332 constexpr int n = f(1);
334 constexpr bool same(const int &a, const int &b) { return &a == &b; } in same()
335 constexpr bool sameTemporary(const int &n) { return same(n, n); } in sameTemporary()
344 constexpr int strcmp_ce(const char *p, const char *q) { in strcmp_ce()
351 constexpr int MangleChars(const Char *p) { in MangleChars()
361 constexpr char c0 = "nought index"[0];
362 constexpr char c1 = "nice index"[10];
363 constexpr char c2 = "nasty index"[12]; // expected-error {{must be initialized by a constant expres…
364 constexpr char c3 = "negative index"[-1]; // expected-error {{must be initialized by a constant exp…
365 constexpr char c4 = ((char*)(int*)"no reinterpret_casts allowed")[14]; // expected-error {{must be …
367 constexpr const char *p = "test" + 2;
370 constexpr const char *max_iter(const char *a, const char *b) { in max_iter()
373 constexpr const char *max_element(const char *a, const char *b) { in max_element()
377 constexpr char str[] = "the quick brown fox jumped over the lazy dog";
378 constexpr const char *max = max_element(begin(str), end(str));
393 constexpr T() : c{"foo"} {} in T()
395 constexpr T t;
408 } constexpr u = { { L"test" }, 0 };
413 constexpr V() : c("hi!") {} in V()
422 constexpr auto Sum(Iter begin, Iter end) -> decltype(+*begin) { in Sum()
426 constexpr int xs[] = { 1, 2, 3, 4, 5 };
427 constexpr int ys[] = { 5, 4, 3, 2, 1 };
428 constexpr int sum_xs = Sum(begin(xs), end(xs));
431 constexpr int ZipFoldR(int (*F)(int x, int y, int c), int n, in ZipFoldR()
441 constexpr int MulAdd(int x, int y, int c) { return x * y + c; } in MulAdd()
442 constexpr int InnerProduct = ZipFoldR(MulAdd, 5, xs, ys, 0);
445 constexpr int SubMul(int x, int y, int c) { return (x - y) * c; } in SubMul()
446 constexpr int DiffProd = ZipFoldR(SubMul, 2, xs+3, ys+3, 1);
452 constexpr const int *p = xs + 3;
453 constexpr int xs4 = p[1]; // ok
454 constexpr int xs5 = p[2]; // expected-error {{constant expression}} expected-note {{read of derefer…
455 constexpr int xs6 = p[3]; // expected-error {{constant expression}} expected-note {{cannot refer to…
456 constexpr int xs0 = p[-3]; // ok
457 constexpr int xs_1 = p[-4]; // expected-error {{constant expression}} expected-note {{cannot refer …
459 constexpr int zs[2][2][2][2] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
467 constexpr int err_zs_1_2_0_0 = zs[1][2][0][0]; // expected-error {{constant expression}} expected-n…
469 constexpr int fail(const int &p) { in fail()
476 constexpr int arr[40] = { 1, 2, 3, [8] = 4 }; // expected-warning {{C99 feature}}
477 constexpr int SumNonzero(const int *p) { in SumNonzero()
480 constexpr int CountZero(const int *p, const int *q) { in CountZero()
487 constexpr ArrayElem() : n(0) {} in ArrayElem()
489 constexpr int f() { return n; } in f()
492 constexpr ArrayRVal() {} in ArrayRVal()
516 struct A { constexpr A(int a, int b) : k(a + b) {} int k; }; in A()
517 constexpr int fn(const A &a) { return a.k; } in fn()
520 struct B { int n; int m; } constexpr b = { 0, b.n }; // expected-warning {{uninitialized}}
522 constexpr C(C *this_) : m(42), n(this_->m) {} // ok in C()
527 constexpr D() : c(&c) {} in D()
532 constexpr E() : p(&p) {} in E()
535 constexpr const E &e1 = E(); // expected-error {{constant expression}} expected-note {{reference to…
538 constexpr E e2 = E();
540 constexpr E e3;
545 constexpr F() : p(&f.p) {} in F()
548 constexpr F f;
552 constexpr T(T *p) : u1(), u2(p) {} in T()
554 constexpr U1() {} in U1()
558 constexpr U2(T *p) : c(p->u1.b) {} in U2()
562 constexpr G() : t(&t) {} in G()
563 } constexpr g;
576 constexpr S(int n, const S *p) : a(5), b(n), p(p), d(n), q("hello") {} in S()
583 constexpr bool CheckS(const S &s) { in CheckS()
590 constexpr Arr() : arr{'x', 'y', 'z'} {} in Arr()
592 constexpr int hash(Arr &&a) { in hash()
595 constexpr int k = hash(Arr());
607 constexpr AggregateInit agg1 = { "hello"[0] };
618 static constexpr const unsigned char uc[] = { "foo" };
625 constexpr B(int n) : a(n) {} in B()
629 constexpr D(int n) : B(n) {} in D()
631 constexpr D d(3);
636 struct Bottom { constexpr Bottom() {} }; in Bottom()
638 constexpr Base(int a = 42, const char *b = "test") : a(a), b(b) {} in Base()
643 constexpr Base2(const int &r) : r(r) {} in Base2()
648 constexpr Derived() : Base(76), Base2(a) {} in Derived()
652 constexpr bool operator==(const Base &a, const Base &b) { in operator ==()
656 constexpr Base base;
657 constexpr Base base2(76);
658 constexpr Derived derived;
669 constexpr Bottom &bot1 = (Base&)derived;
670 constexpr Bottom &bot2 = (Base2&)derived;
673 constexpr Bottom *pb1 = (Base*)&derived;
674 constexpr Bottom *pb2 = (Base2*)&derived;
679 constexpr Base2 &fail = (Base2&)bot1; // expected-error {{constant expression}} expected-note {{can…
680 constexpr Base &fail2 = (Base&)*pb2; // expected-error {{constant expression}} expected-note {{cann…
681 constexpr Base2 &ok2 = (Base2&)bot2;
684 constexpr Base2 *pfail = (Base2*)pb1; // expected-error {{constant expression}} expected-note {{can…
685 constexpr Base *pfail2 = (Base*)&bot2; // expected-error {{constant expression}} expected-note {{ca…
686 constexpr Base2 *pok2 = (Base2*)pb2;
692 constexpr Base *nullB = 42 - 6 * 7;
700 constexpr T(int n) : k(5*n - 3) {} in T()
701 constexpr operator int() { return k; } in operator int()
706 constexpr S(int n) : k(2*n + 1) {} in S()
707 constexpr operator int() { return k; } in operator int()
708 constexpr operator T() { return T(k); } in operator T()
712 constexpr bool check(T a, T b) { return a == b.k; } in check()
724 constexpr S() {} in S()
725 constexpr int f();
728 constexpr T(int n) : S(), n(n) {} in T()
731 constexpr int S::f() { in f()
742 constexpr int f(const S &s) { in f()
745 constexpr int n = f(T(5));
748 constexpr bool b(int n) { return &n; } in b()
760 constexpr U u[4] = { { .a = 0 }, { .b = 1 }, { .a = 2 }, { .b = 3 } }; // expected-warning 4{{C99 f…
768 constexpr U v = {};
772 constexpr Empty e = {};
775 constexpr U x = {42};
776 constexpr U y = x;
784 constexpr A(int n) : n(n) {} in A()
786 constexpr int f() { return n + 3; } in f()
788 constexpr A a(7);
795 constexpr B(int n, int m) : A(n), m(m) {} in B()
797 constexpr int g() { return n + m + 1; } in g()
799 constexpr B b(9, 13);
814 constexpr S(int m, int n, int (S::*pf)() const, int S::*pn) : in S()
816 constexpr S() : m(), n(), pf(&S::f), pn(&S::n) {} in S()
818 constexpr int f() { return this->*pn; } in f()
826 constexpr int S::*pm = &S::m;
827 constexpr int S::*pn = &S::n;
828 constexpr int (S::*pf)() const = &S::f;
829 constexpr int (S::*pg)() const = &S::g;
831 constexpr S s(2, 5, &S::f, &S::m);
855 constexpr int (T<10>::*deepn) = &T<0>::n;
859 constexpr int (T<15>::*deepm) = (int(T<10>::*))&T<30>::m;
860 constexpr int *pbad = &(t17.*deepm); // expected-error {{constant expression}}
865 constexpr T<5> *p17_5 = &t17;
866 constexpr T<13> *p17_13 = (T<13>*)p17_5;
867constexpr T<23> *p17_23 = (T<23>*)p17_13; // expected-error {{constant expression}} expected-note …
870 constexpr int *pbad2 = &(p17_13->*(int(T<9>::*))deepm); // expected-error {{constant expression}}
872 constexpr T<5> *p30_5 = &t30;
873 constexpr T<23> *p30_23 = (T<23>*)p30_5;
874 constexpr T<13> *p30_13 = p30_23;
894 constexpr Base() {} in Base()
898 constexpr Derived() {} in Derived()
899 constexpr const int *f() { return &n; } in f()
902 constexpr Derived a[10];
903 constexpr Derived *pd3 = const_cast<Derived*>(&a[3]);
904 constexpr Base *pb3 = const_cast<Derived*>(&a[3]);
908 constexpr Base *pb4 = pb3 + 1; // ok, one-past-the-end pointer.
909constexpr int pb4n = pb4->n; // expected-error {{constant expression}} expected-note {{cannot acce…
910constexpr Base *err_pb5 = pb3 + 2; // expected-error {{constant expression}} expected-note {{canno…
911constexpr int err_pb5n = err_pb5->n; // expected-error {{constant expression}} expected-note {{ini…
912constexpr Base *err_pb2 = pb3 - 1; // expected-error {{constant expression}} expected-note {{canno…
913constexpr int err_pb2n = err_pb2->n; // expected-error {{constant expression}} expected-note {{ini…
914 constexpr Base *pb3a = pb4 - 1;
917constexpr Derived *err_pd4 = (Derived*)pb4; // expected-error {{constant expression}} expected-not…
918 constexpr Derived *pd3a = (Derived*)pb3a;
919 constexpr int pd3n = pd3a->n;
922 constexpr Derived *pd6 = pd3a + 3;
924 constexpr Derived *pd9 = pd6 + 3;
925 constexpr Derived *pd10 = pd6 + 4;
926 constexpr int pd9n = pd9->n; // ok
927constexpr int err_pd10n = pd10->n; // expected-error {{constant expression}} expected-note {{canno…
928 constexpr int pd0n = pd10[-10].n;
929constexpr int err_pdminus1n = pd10[-11].n; // expected-error {{constant expression}} expected-note…
931 constexpr Base *pb9 = pd9;
932 constexpr const int *(Base::*pfb)() const =
942 constexpr complex(int re = 0, int im = 0) : re(re), im(im) {} in complex()
943 constexpr complex(const complex &o) : re(o.re), im(o.im) {} in complex()
944 constexpr complex operator-() const { return complex(-re, -im); } in operator -()
945 friend constexpr complex operator+(const complex &l, const complex &r) { in operator +()
948 friend constexpr complex operator-(const complex &l, const complex &r) { in operator -()
951 friend constexpr complex operator*(const complex &l, const complex &r) { in operator *()
954 friend constexpr bool operator==(const complex &l, const complex &r) { in operator ==()
957 constexpr bool operator!=(const complex &r) const { in operator !=()
960 constexpr int real() const { return re; } in real()
961 constexpr int imag() const { return im; } in imag()
964 constexpr complex i = complex(0, 1);
965 constexpr complex k = (3 + 4*i) * (6 - 4*i);
976 constexpr complex makeComplex(int re, int im) { return complex(re, im); } in makeComplex()
982 constexpr complex_wrap(int re, int im = 0) : complex(re, im) {} in complex_wrap()
983 constexpr complex_wrap(const complex_wrap &o) : complex(o) {} in complex_wrap()
990 constexpr complex_wrap makeComplexWrap(int re, int im) { in makeComplexWrap()
999 struct A { constexpr bool operator==(int x) { return true; } }; in operator ==()
1003constexpr bool f(int k) { // expected-error {{constexpr function never produces a constant express… in f()
1010 constexpr int get(bool FromA) { return FromA ? A().get() : 1; } in get()
1011 constexpr int n = get(false);
1016 volatile constexpr int n1 = 0; // expected-note {{here}}
1020 constexpr int m1 = n1; // expected-error {{constant expression}} expected-note {{read of volatile-q…
1021 constexpr int m2 = n2; // expected-error {{constant expression}} expected-note {{read of volatile-q…
1022 constexpr int m1b = const_cast<const int&>(n1); // expected-error {{constant expression}} expected-…
1023 constexpr int m2b = const_cast<const int&>(n2); // expected-error {{constant expression}} expected-…
1028 constexpr int f(volatile int &&r) { in f()
1031 constexpr int g(volatile int &&r) { in g()
1044 extern constexpr int n = 0;
1045 extern constexpr int m; // expected-error {{constexpr variable declaration must be a definition}}
1047 … extern constexpr int i; // expected-error {{constexpr variable declaration must be a definition}} in f()
1048 constexpr int j = 0; in f()
1049 constexpr int k; // expected-error {{default initialization of an object of const type}} in f()
1054 constexpr _Complex float test1 = {};
1055 constexpr _Complex float test2 = {1};
1056 constexpr _Complex double test3 = {1,2};
1057 constexpr _Complex int test4 = {4};
1058 constexpr _Complex int test5 = 4;
1059 constexpr _Complex int test6 = {5,6};
1061 constexpr fcomplex test7 = fcomplex();
1063 constexpr const double &t2r = __real test3;
1064 constexpr const double &t2i = __imag test3;
1068 constexpr const double *t2p = &t2r;
1074 constexpr _Complex float *p = 0;
1075constexpr float pr = __real *p; // expected-error {{constant expr}} expected-note {{cannot access …
1076constexpr float pi = __imag *p; // expected-error {{constant expr}} expected-note {{cannot access …
1077 constexpr const _Complex double *q = &test3 + 1;
1078constexpr double qr = __real *q; // expected-error {{constant expr}} expected-note {{cannot access…
1079constexpr double qi = __imag *q; // expected-error {{constant expr}} expected-note {{cannot access…
1087 template<int x> constexpr int f() { return x; } in f()
1096 constexpr int k = 4;
1127 constexpr S(int a, int b, int d, int e) : a(a), b(b), d(d), e(e) {} in S()
1128 constexpr S(int c, int d, int f) : c(c), d(d), f(f) {} in S()
1131 constexpr S s1(1, 2, 3, 4);
1132 constexpr S s2(5, 6, 7);
1155 } constexpr mm = { 4 };
1156constexpr int mmn = mm.n; // expected-error {{constant expression}} expected-note {{read of mutabl…
1158constexpr int mmn2 = mm.n; // expected-error {{constant expression}} expected-note {{read of mutab…
1163 constexpr MM m = { 0 }; in f()
1171 constexpr C c[3] = {};
1172 constexpr int k = c[1].b.a.n; // expected-error {{constant expression}} expected-note {{mutable}}
1181constexpr int n = (int)(char*)123; // expected-error {{constant expression}} expected-note {{reint…
1182 constexpr int m = fold((int)(char*)123); // ok
1191 constexpr const int &f(const int &n) { return n; } in f()
1192 constexpr int k1 = f(0); // ok
1197 constexpr const Wrap &g(const Wrap &w) { return w; } in g()
1198 constexpr int k2 = g({0}).value; // ok
1200 constexpr const int &i = 0; // expected-error {{constant expression}} expected-note {{temporary}} e…
1201 constexpr const int j = i; // expected-error {{constant expression}} expected-note {{initializer of…
1207 constexpr auto LastNonzero(Iter p, Iter q) -> decltype(+*p) { in LastNonzero()
1211 constexpr int arr1[] = { 1, 0, 0, 3, 0, 2, 0, 4, 0, 0 };
1214 constexpr int arr2[] = { 1, 0, 0, 3, 0, 2, 0, 4, 0, 5 };
1222 constexpr int n = 1 + in f()
1235constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expres…
1240 constexpr VI4 f(int n) { in f()
1243 constexpr auto v1 = f(10);
1246 constexpr VD4 g(int n) { in g()
1249 constexpr auto v2 = g(4);