1 /* PR c++/93804 - exempt extern "C" headers from -Wredundant-tags 2 Verify that -Wredundant-tags is not issued for redundant class-key 3 in extern "C" references in a header file. 4 { dg-do compile } 5 { dg-options "-Wredundant-tags -ftrack-macro-expansion=0" } */ 6 7 # 1 "Wredundant-tags-4.C" 8 # 1 "Wredundant-tags-4.h" 1 9 # line 10 10 11 #if __cplusplus >= 201103L 12 # define enum_struct enum struct 13 #else 14 # define enum_struct class 15 #endif 16 17 extern "C" { 18 19 class C1 { }; 20 enum E1 { }; 21 enum_struct ES1 { }; 22 struct S1 { enum E1 e1; }; 23 union U1 { enum E1 e1; struct S1 s1; }; 24 25 /* The warning should be issued for the class-key class even in 26 an extern "C" block. */ 27 void f0 (class C1); // { dg-warning "\\\[-Wredundant-tags" } 28 void f1 (enum E1); // { dg-bogus "\\\[-Wredundant-tags" } 29 30 /* Ditto for a scoped enum. */ 31 void f2 (enum_struct ES1); // { dg-warning "\\\[-Wredundant-tags" } 32 // { dg-warning "must not use the 'struct' keyword" "enum struct" { target { c++11 } } .-1 } 33 34 void f3 (struct S1); // { dg-bogus "\\\[-Wredundant-tags" } 35 void f4 (union U1); // { dg-bogus "\\\[-Wredundant-tags" } 36 37 inline int finline1(class C1)38 finline1 (class C1) // { dg-warning "\\\[-Wredundant-tags" } 39 { return sizeof (class C1); } // { dg-warning "\\\[-Wredundant-tags" } 40 41 inline int finline2(enum E1)42 finline2 (enum E1) // { dg-bogus "\\\[-Wredundant-tags" } 43 { return sizeof (enum E1); } // { dg-bogus "\\\[-Wredundant-tags" } 44 45 inline int finline3(enum_struct ES1)46 finline3 (enum_struct ES1) // { dg-warning "\\\[-Wredundant-tags" } 47 { return sizeof (ES1); } 48 49 inline int finline4(struct S1)50 finline4 (struct S1) // { dg-bogus "\\\[-Wredundant-tags" } 51 { return sizeof (struct S1); } 52 53 inline int finline5(union U1)54 finline5 (union U1) // { dg-bogus "\\\[-Wredundant-tags" } 55 { return sizeof (union U1); } 56 57 extern class C1 c1; // { dg-warning "\\\[-Wredundant-tags" } 58 extern enum E1 e1; // { dg-bogus "\\\[-Wredundant-tags" } 59 extern enum_struct ES1 es1; // { dg-warning "\\\[-Wredundant-tags" } 60 extern struct S1 s1; // { dg-bogus "\\\[-Wredundant-tags" } 61 extern union U1 u1; // { dg-bogus "\\\[-Wredundant-tags" } 62 63 namespace N1 { 64 /* Verify that -Wredundant-tags is issued in a namespace enclosed 65 in an extern "C" block. (Such code cannot be shared with C.) */ 66 extern class C1 n1c1; // { dg-warning "\\\[-Wredundant-tags" } 67 extern enum E1 n1e1; // { dg-warning "\\\[-Wredundant-tags" } 68 extern enum_struct ES1 n1es1; // { dg-warning "\\\[-Wredundant-tags" } 69 extern struct S1 n1s1; // { dg-warning "\\\[-Wredundant-tags" } 70 extern union U1 n1u1; // { dg-warning "\\\[-Wredundant-tags" } 71 } 72 } // extern "C" 73 74 75 extern "C++" { 76 77 class C2 { }; 78 enum E2 { }; 79 enum_struct ES2 { }; 80 struct S2 { 81 enum E2 e21; // { dg-warning "\\\[-Wredundant-tags" } 82 E2 e22; 83 enum_struct ES2 es21; // { dg-warning "\\\[-Wredundant-tags" } 84 ES2 es22; 85 }; 86 union U2 { }; 87 88 void f5 (class C2); // { dg-warning "\\\[-Wredundant-tags" } 89 void f6 (enum E2); // { dg-warning "\\\[-Wredundant-tags" } 90 void f7 (enum_struct ES2); // { dg-warning "\\\[-Wredundant-tags" } 91 void f8 (struct S2); // { dg-warning "\\\[-Wredundant-tags" } 92 void f9 (union U2); // { dg-warning "\\\[-Wredundant-tags" } 93 94 extern class C2 c2; // { dg-warning "\\\[-Wredundant-tags" } 95 extern enum E2 e2; // { dg-warning "\\\[-Wredundant-tags" } 96 extern enum_struct ES2 es2; // { dg-warning "\\\[-Wredundant-tags" } 97 extern struct S2 s2; // { dg-warning "\\\[-Wredundant-tags" } 98 extern union U2 u2; // { dg-warning "\\\[-Wredundant-tags" } 99 } // extern "C++" 100 101 102 namespace N { 103 104 class C3 { }; 105 enum E3 { }; 106 enum_struct ES3 { }; 107 struct S3 { }; 108 union U3 { }; 109 110 void f10 (class C3); // { dg-warning "\\\[-Wredundant-tags" } 111 void f11 (enum E3); // { dg-warning "\\\[-Wredundant-tags" } 112 void f12 (enum_struct ES3); // { dg-warning "\\\[-Wredundant-tags" } 113 void f13 (struct S3); // { dg-warning "\\\[-Wredundant-tags" } 114 void f14 (union U3); // { dg-warning "\\\[-Wredundant-tags" } 115 116 extern class C3 c3; // { dg-warning "\\\[-Wredundant-tags" } 117 extern enum E3 e3; // { dg-warning "\\\[-Wredundant-tags" } 118 extern enum_struct ES3 es3; // { dg-warning "\\\[-Wredundant-tags" } 119 extern struct S3 s3; // { dg-warning "\\\[-Wredundant-tags" } 120 extern union U3 u3; // { dg-warning "\\\[-Wredundant-tags" } 121 122 extern "C" { 123 124 /* Verify that -Wredundant-tags is issued in an extern "C" block 125 enclosed within a namespace. (Such code cannot be shared with 126 C.) */ 127 class C4 { }; 128 enum E4 { }; 129 enum_struct ES4 { }; 130 struct S4 { }; 131 union U4 { }; 132 133 extern class C4 c4; // { dg-warning "\\\[-Wredundant-tags" } 134 extern enum E4 e4; // { dg-warning "\\\[-Wredundant-tags" } 135 extern enum_struct ES4 es4; // { dg-warning "\\\[-Wredundant-tags" } 136 extern struct S4 s4; // { dg-warning "\\\[-Wredundant-tags" } 137 extern union U4 u4; // { dg-warning "\\\[-Wredundant-tags" } 138 } 139 140 } // namespace N 141 142 // { dg-prune-output "must not use the 'struct' keyword" } 143