Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/cpp0x/addressof1.C @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
16 static_assert (__builtin_addressof (j) == &i, ""); | 16 static_assert (__builtin_addressof (j) == &i, ""); |
17 static_assert (addressof (j) == &i, ""); | 17 static_assert (addressof (j) == &i, ""); |
18 | 18 |
19 struct S { int s; } s; | 19 struct S { int s; } s; |
20 static_assert (__builtin_addressof (s) == &s, ""); | 20 static_assert (__builtin_addressof (s) == &s, ""); |
21 static_assert ((int *) __builtin_addressof (s) == &s.s, ""); | |
22 static_assert (addressof (s) == &s, ""); | 21 static_assert (addressof (s) == &s, ""); |
23 static_assert ((int *) addressof (s) == &s.s, ""); | |
24 | 22 |
25 struct T | 23 struct T |
26 { | 24 { |
27 static T tt; | 25 static T tt; |
28 constexpr T () : p (addressof (tt)) {} | 26 constexpr T () : p (addressof (tt)) {} |
29 constexpr T *operator & () const { return p; } | 27 constexpr T *operator & () const { return p; } |
30 T *p; | 28 T *p; |
31 }; | 29 }; |
32 constexpr T t; | 30 constexpr T t; |
33 T T::tt; | 31 T T::tt; |
34 static_assert (__builtin_addressof (t) == (const T *) &t.p, ""); | |
35 static_assert (&t == __builtin_addressof (T::tt), ""); | 32 static_assert (&t == __builtin_addressof (T::tt), ""); |
36 static_assert (addressof (t) == (const T *) &t.p, ""); | |
37 static_assert (&t == addressof (T::tt), ""); | 33 static_assert (&t == addressof (T::tt), ""); |
38 | 34 |
39 struct S x, y; | 35 struct S x, y; |
40 | 36 |
41 constexpr S * | 37 constexpr S * |
74 | 70 |
75 constexpr int a = 1; | 71 constexpr int a = 1; |
76 static_assert (__builtin_addressof (a) == &a, ""); | 72 static_assert (__builtin_addressof (a) == &a, ""); |
77 static_assert (addressof (a) == &a, ""); | 73 static_assert (addressof (a) == &a, ""); |
78 constexpr int c[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | 74 constexpr int c[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
79 static_assert ((const int *) __builtin_addressof (c) == &c[0], ""); | |
80 static_assert ((const int *) addressof (c) == &c[0], ""); | |
81 | 75 |
82 void | 76 void |
83 baz () | 77 baz () |
84 { | 78 { |
85 } | 79 } |
91 || addressof (T::tt) == addressof (t) | 85 || addressof (T::tt) == addressof (t) |
92 || &T::tt != &t | 86 || &T::tt != &t |
93 || __builtin_addressof (baz) != baz | 87 || __builtin_addressof (baz) != baz |
94 || addressof (baz) != baz) | 88 || addressof (baz) != baz) |
95 __builtin_abort (); | 89 __builtin_abort (); |
90 | |
91 // reinterpret casts are not constexprs | |
92 if (! (((int *) __builtin_addressof (s) == &s.s) | |
93 && ((int *) addressof (s) == &s.s) | |
94 && (__builtin_addressof (t) == (const T *) &t.p) | |
95 && (addressof (t) == (const T *) &t.p) | |
96 && ((const int *) __builtin_addressof (c) == &c[0]) | |
97 && ((const int *) addressof (c) == &c[0]))) | |
98 __builtin_abort (); | |
99 | |
100 return 0; | |
96 } | 101 } |