comparison gcc/testsuite/g++.dg/warn/Wredundant-tags.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* PR c++/61339 - add mismatch between struct and class
2 Test to verify that -Wredundant-tags is issued for references to class
3 types that use the class-key even though they don't need to.
4 { dg-do compile }
5 { dg-options "-Wredundant-tags" } */
6
7 struct A;
8
9 extern A *pa;
10 extern struct A *pa; // { dg-warning "redundant class-key 'struct' in reference to 'struct A'" }
11
12 extern A aa[];
13 extern struct A aa[]; // { dg-warning "redundant class-key 'struct' in reference to 'struct A'" }
14
15 void func (A*);
16 void func (struct A*); // { dg-warning "redundant class-key 'struct' in reference to 'struct A'" }
17
18 int A;
19
20 extern struct A *pa;
21 extern struct A aa[];
22 void func (struct A*);
23
24
25 class B;
26
27 extern B *pb;
28 extern class B *pb; // { dg-warning "redundant class-key 'class' in reference to 'class B'" }
29
30 extern B ab[];
31 extern class B ab[]; // { dg-warning "redundant class-key 'class' in reference to 'class B'" }
32
33 void func (B*);
34 void func (class B*); // { dg-warning "redundant class-key 'class' in reference to 'class B'" }
35
36 int B;
37
38 extern class B *pb;
39 extern class B ab[];
40 void func (class B*);
41
42
43 enum C { c0 };
44
45 extern C *pc;
46 extern enum C *pc; // { dg-warning "redundant enum-key 'enum' in reference to 'enum C'" }
47
48 extern C ac[];
49 extern enum C ac[]; // { dg-warning "redundant enum-key 'enum' in reference to 'enum C'" }
50
51 void func (C*);
52 void func (enum C*); // { dg-warning "redundant enum-key 'enum' in reference to 'enum C'" }
53
54 int C;
55
56 extern enum C *pc;
57 extern enum C ac[];
58 void func (enum C*);
59
60
61 #if __cplusplus > 199711L
62
63 enum class D1 { d1 };
64 enum struct D2 { d2 };
65
66 #else
67
68 enum D1 { d1 };
69 enum D2 { d2 };
70
71 #endif
72
73 extern D1 *pd1;
74 extern D2 *pd2;
75 extern enum D1 *pd1; // { dg-warning "redundant enum-key 'enum' in reference to 'enum class D1'" "C++ 11 and above" { target c++11 } }
76 // { dg-warning "redundant enum-key 'enum' in reference to 'enum D1'" "C++ 98" { target c++98_only } .-1 }
77
78 extern enum D2 *pd2; // { dg-warning "redundant enum-key 'enum' in reference to 'enum class D2'" "C++ 11 and above" { target c++11 } }
79 // { dg-warning "redundant enum-key 'enum' in reference to 'enum D2'" "C++ 98" { target c++98_only } .-1 }
80
81 extern D1 ad1[];
82 extern D2 ad2[];
83
84 #if __cplusplus > 199711L
85 extern enum class D1 ad1[]; // { dg-warning "redundant enum-key 'enum class' in reference to 'enum class D1'" "C++ 11 and above" { target c++11 } }
86 // { dg-warning "elaborated-type-specifier for a scoped enum must not use the 'class' keyword" "C++ 11 and above" { target c++11 } .-1 }
87 /* The pretty printer cannot differentiate between enum class and enum struct
88 because the C++ front-end doesn't encode it so allow for both in the text
89 of the warning below. */
90 extern enum struct D2 ad2[]; // { dg-warning "redundant enum-key 'enum struct' in reference to 'enum \(class|struct\) D2'" "C++ 11 and above" { target c++11 } }
91 // { dg-warning "elaborated-type-specifier for a scoped enum must not use the 'struct' keyword" "C++ 11 and above" { target c++11 } .-1 }
92 #else
93 extern enum D1 ad1[]; // { dg-warning "redundant enum-key 'enum' in reference to 'enum D1'" "C++ 98" { target c++98_only } }
94 #endif
95
96 void func (D1*);
97 void func (enum D1*); // { dg-warning "redundant enum-key 'enum' in reference to 'enum " }
98
99 void func (D2*);
100 void func (enum D2*); // { dg-warning "redundant enum-key 'enum' in reference to 'enum " }
101
102 int D1, D2;
103
104 extern enum D1 *pd1;
105 extern enum D1 ad1[];
106 void func (enum D1*);
107
108 extern enum D2 *pd2;
109 extern enum D2 ad2[];
110 void func (enum D2*);
111
112
113 union U;
114
115 extern U *pu;
116 extern union U *pu; // { dg-warning "redundant class-key 'union' in reference to 'union U'" }
117
118 extern U au[];
119 extern union U au[]; // { dg-warning "redundant class-key 'union' in reference to 'union U'" }
120
121 void func (U*);
122 void func (union U*); // { dg-warning "redundant class-key 'union' in reference to 'union U'" }
123
124 int U;
125
126 extern union U *pu;
127 extern union U au[];
128 void func (union U*);