Debian Codegraph @

gcc/testsuite/g++.dg/init/array59.C

raw
1 /* PR c++/94510 - nullptr_t implicitly cast to zero twice in std::array
2 { dg-do compile { target c++11 } } */
3
4 namespace std {
5 typedef __typeof__ (nullptr) nullptr_t;
6 }
7
8 int ia1[2] = { nullptr }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
9 int ia2[2] = { nullptr, 0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
10 int ia3[] = { nullptr, 0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
11
12 int ia4[2] = { (std::nullptr_t)0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
13 int ia5[2] = { (std::nullptr_t)0, 0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
14 int ia6[] = { (std::nullptr_t)0, 0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'int'" }
15
16
17 const char ca1[2] = { nullptr, 0 }; // { dg-error "cannot convert 'std::nullptr_t' to 'const char'" }
18
19 const char ca2[2] = { (char*)nullptr, 0 };// { dg-error "invalid conversion from 'char\\\*' to 'char'" }
20
21 const char ca3[2] = { std::nullptr_t () };// { dg-error "cannot convert 'std::nullptr_t'" }
22
23 /* Verify that arrays of member pointers can be initialized by a literal
24 zero as well as nullptr. */
25
26 struct S { };
27 typedef int S::*MemPtr;
28 typedef int (S::*MemFuncPtr)();
29
30 MemPtr mp1[3] = { 0, nullptr, (MemPtr)0 };
31 MemPtr mp2[3] = { 0, std::nullptr_t (), MemPtr () };
32
33 MemPtr mp3[3] = { 0, (void*)0 }; // { dg-error "cannot convert 'void\\\*' to 'MemPtr' " }
34 MemPtr mp4[3] = { 0, (S*)0 }; // { dg-error "cannot convert 'S\\\*' to 'MemPtr' " }
35 MemPtr mp5[3] = { 0, S () }; // { dg-error "cannot convert 'S' to 'MemPtr' " }
36
37 MemFuncPtr mfp1[3] = { 0, nullptr, (MemFuncPtr)0 };
38 MemFuncPtr mfp2[3] = { 0, std::nullptr_t (), MemFuncPtr () };
39
40 MemFuncPtr mfp3[3] = { 0, (void*)0 }; // { dg-error "cannot convert 'void\\\*' to 'MemFuncPtr' " }
41 MemFuncPtr mfp4[3] = { 0, (S*)0 }; // { dg-error "cannot convert 'S\\\*' to 'MemFuncPtr' " }
42 MemFuncPtr mfp5[3] = { 0, S () }; // { dg-error "cannot convert 'S' to 'MemFuncPtr' " }