| 1 |
// PR c++/89833 |
| 2 |
// Test to verify that arrays of null pointer to members used as |
| 3 |
// non-type template arguments are interprested as null regardless |
| 4 |
// of the form of their initialization. |
| 5 |
// { dg-do compile { target c++20 } } |
| 6 |
// { dg-options "-O2 -Wall -fdump-tree-optimized" } |
| 7 |
|
| 8 |
struct A { int i; }; |
| 9 |
|
| 10 |
typedef int A::*pam_t; |
| 11 |
|
| 12 |
struct B { pam_t a[2]; }; |
| 13 |
template <B x> struct C { static constexpr B b = x; }; |
| 14 |
|
| 15 |
B f__ () { return B{ }; } |
| 16 |
B f0_ () { return B{ 0 }; } |
| 17 |
B f00 () { return B{ 0, 0 }; } |
| 18 |
|
| 19 |
typedef C<B{ }> X__; |
| 20 |
typedef C<B{ 0 }> X0_; |
| 21 |
typedef C<B{ 0, 0 }> X00; |
| 22 |
|
| 23 |
B g__ () { return X__::b; } |
| 24 |
B g0_ () { return X0_::b; } |
| 25 |
B g00 () { return X00::b; } |
| 26 |
|
| 27 |
const B b__{ }; |
| 28 |
const B b0_{ 0 }; |
| 29 |
const B b00{ 0, 0 }; |
| 30 |
|
| 31 |
const pam_t apam__[2] = { }; |
| 32 |
const pam_t apam0_[2] = { 0 }; |
| 33 |
const pam_t apam00[2] = { 0, 0 }; |
| 34 |
|
| 35 |
#define assert(expr) \ |
| 36 |
(expr) ? (void)0 : __builtin_abort () |
| 37 |
|
| 38 |
void test () |
| 39 |
{ |
| 40 |
assert (f__ ().a[0] == nullptr && f__ ().a[1] == nullptr); |
| 41 |
assert (f0_ ().a[0] == nullptr && f0_ ().a[1] == nullptr); |
| 42 |
assert (f00 ().a[0] == nullptr && f00 ().a[1] == nullptr); |
| 43 |
|
| 44 |
assert (g__ ().a[0] == nullptr && g__ ().a[1] == nullptr); |
| 45 |
assert (g0_ ().a[0] == nullptr && g0_ ().a[1] == nullptr); |
| 46 |
assert (g00 ().a[0] == nullptr && g00 ().a[1] == nullptr); |
| 47 |
|
| 48 |
assert (b__.a[0] == nullptr && b__.a[1] == nullptr); |
| 49 |
assert (b0_.a[0] == nullptr && b0_.a[1] == nullptr); |
| 50 |
assert (b00.a[0] == nullptr && b00.a[1] == nullptr); |
| 51 |
|
| 52 |
assert (apam__[0] == nullptr && apam__[1] == nullptr); |
| 53 |
assert (apam0_[0] == nullptr && apam0_[1] == nullptr); |
| 54 |
assert (apam00[0] == nullptr && apam00[1] == nullptr); |
| 55 |
} |
| 56 |
|
| 57 |
// { dg-final { scan-tree-dump-not "abort" "optimized" } } |