Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/launder2.C

raw
1 // { dg-do compile { target c++11 } }
2
3 int a;
4 int *b = __builtin_launder (); // { dg-error "wrong number of arguments to" }
5 int *c = __builtin_launder (&a, 2); // { dg-error "wrong number of arguments to" }
6 int *d = __builtin_launder (&a);
7 int e = __builtin_launder (a); // { dg-error "not a pointer to object type" }
8 int &f = a;
9 int g = __builtin_launder (f); // { dg-error "not a pointer to object type" }
10
11 template <typename T> T f1 (T x) { return __builtin_launder (x); } // { dg-error "not a pointer to object type" }
12 template <typename T> T f2 (T x) { return __builtin_launder (x); }
13
14 int h = f1 (a);
15 int *i = f2 (&a);
16 struct S { long s; int foo (); } *j;
17 S *k = f2 (j);
18 int l = __builtin_launder (j)->foo ();
19
20 template <typename T> T *f3 (T *x) { return __builtin_launder (x); }
21
22 long *m;
23 long *n = f3 (m);
24 int *o = f3 (&a);
25
26 template <typename T, typename... U> T *f4 (U... x) { return __builtin_launder (x...); }
27 template <typename T, typename... U> T *f5 (U... x) { return __builtin_launder (x...); } // { dg-error "wrong number of arguments to" }
28 template <typename T, typename... U> T *f6 (U... x) { return __builtin_launder (x...); } // { dg-error "wrong number of arguments to" }
29 template <typename T, typename... U> T f7 (T x, U... y) { return __builtin_launder (x, y...); } // { dg-error "wrong number of arguments to" }
30
31 long *p = f4<long, long *> (m);
32 long *q = f5<long> ();
33 long *r = f6<long, long *, int> (m, 1);
34 S s;
35 int t = __builtin_launder (&s)->foo ();
36
37 constexpr const int *f8 (const int *x) { return __builtin_launder (x); }
38 template <typename T> constexpr T f9 (T x) { return __builtin_launder (x); }
39 constexpr int u = 6;
40 constexpr const int *v = f8 (&u);
41 constexpr const int *w = f9 (&u);
42 static_assert (*f8 (&u) == 6 && *f9 (&u) == 6, "");