Debian Codegraph @

gcc/testsuite/g++.dg/lookup/name-clash11.C

raw
1 // PR c++/69023 - bitset whose name is used in constant-expression rejected
2 // Test also verifies the correct evaluation of the expressions with
3 // -fpermissive.
4 // { dg-options "-fpermissive" }
5
6 #if __cplusplus >= 201103L
7 # define ASSERT(e) static_assert (e, #e)
8 #else
9 # define ASSERT(e) \
10 do { typedef int asrt[bool(e) ? 1 : -1]; } while (0)
11 #endif
12
13
14 void test_bitset ()
15 {
16 int x; // { dg-message "declared here" }
17
18 {
19 struct S {
20 int x: sizeof x; // { dg-warning "changes meaning" }
21 };
22 }
23 }
24
25 void test_enum ()
26 {
27 // Also exercise (not covered by c++/69023):
28 int y; // { dg-message "declared here" }
29 {
30 struct S {
31 enum E {
32 y = sizeof y // { dg-warning "9:declaration of .y. changes meaning" }
33 };
34
35 // Verify the enumerator has the correct value.
36 void test () { ASSERT (y == sizeof (int)); }
37 };
38 }
39 }
40
41 void test_alignas ()
42 {
43 enum { A = 16 }; // { dg-message "declared here" }
44 {
45 struct S {
46 #if __cplusplus >= 201103L
47 alignas (A)
48 #else
49 __attribute__ ((aligned (A)))
50 #endif
51 int A; // { dg-warning "changes meaning" }
52
53 // Verify the member has the correct alignment.
54 void test () { ASSERT (__alignof__ (this->A) == 16); }
55 };
56 }
57 }
58
59 void test_array ()
60 {
61 enum { A = 16 }; // { dg-message "declared here" }
62 {
63 struct S {
64 int A [A]; // { dg-warning "changes meaning" }
65
66 // Verify the member has the correct alignment.
67 void test () { ASSERT (sizeof (this->A) == 16 * sizeof (int)); }
68 };
69 }
70 }
71
72 void test_vector ()
73 {
74 enum { A = 16 }; // { dg-message "declared here" }
75 {
76 struct S {
77 int A __attribute__ ((vector_size (A))); // { dg-warning "changes meaning" }
78
79 // Verify the member has the correct size.
80 void test () { ASSERT (sizeof (this->A) == 16); }
81 };
82 }
83 }
84