annotate gcc/testsuite/gcc.dg/c99-tag-3.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test for handling of tags. "const struct foo;" and similar does
kono
parents:
diff changeset
2 not redeclare an existing tag. */
kono
parents:
diff changeset
3 /* Origin: Joseph Myers <jsm@polyomino.org.uk> */
kono
parents:
diff changeset
4 /* { dg-do compile } */
kono
parents:
diff changeset
5 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 /* Plain "struct s;" always declares a tag: the same as one declared
kono
parents:
diff changeset
8 in that scope, or shadowing one from an outer scope. */
kono
parents:
diff changeset
9 struct s0;
kono
parents:
diff changeset
10 struct s0 { int a; };
kono
parents:
diff changeset
11 struct s0;
kono
parents:
diff changeset
12 void f (void) { struct s0; }
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 /* A declaration with a qualifier or storage class specifier declares
kono
parents:
diff changeset
15 the tag if no other declaration of it is visible. */
kono
parents:
diff changeset
16 const union u0; /* { dg-warning "13:useless type qualifier in empty declaration" } */
kono
parents:
diff changeset
17 union u0 { long b; };
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 extern struct s1; /* { dg-warning "15:useless storage class specifier in empty declaration" } */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* But if a declaration of the tag is visible, whether at the same
kono
parents:
diff changeset
22 scope or an outer scope, the declaration specifies the same type as
kono
parents:
diff changeset
23 the previous declaration and does not redeclare the tag (C99
kono
parents:
diff changeset
24 6.7.2.3#8). Thus, as it does not declare a declarator, a tag or
kono
parents:
diff changeset
25 the members of an enumeration, it is a constraint violation. */
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 struct s2 { char x; };
kono
parents:
diff changeset
28 const struct s2; /* { dg-error "14:empty declaration with type qualifier does not redeclare tag" } */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 union u1;
kono
parents:
diff changeset
31 extern union u1; /* { dg-error "14:empty declaration with storage class specifier does not redeclare tag" } */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 union u2 { long b; };
kono
parents:
diff changeset
34 void g(void) { const union u2; } /* { dg-error "28:empty declaration with type qualifier does not redeclare tag" } */
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* And it does not redeclare the tag either if the outer tag is the
kono
parents:
diff changeset
37 wrong kind of tag. This also yields an error for the reference to
kono
parents:
diff changeset
38 the wrong kind of tag in addition to the pedwarn for the empty
kono
parents:
diff changeset
39 declaration. */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 union u3 { float v; };
kono
parents:
diff changeset
42 void h(void) { const struct u3; } /* { dg-error "29:'u3' defined as wrong kind of tag" } */
kono
parents:
diff changeset
43 /* { dg-error "29:empty declaration with type qualifier does not redeclare tag" "wrong tag empty" { target *-*-* } .-1 } */
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 /* However, such useless specifiers are OK if the contents of the tag
kono
parents:
diff changeset
46 are being defined, or shadowed in an inner scope with the contents
kono
parents:
diff changeset
47 included in the shadowing. */
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 struct s3;
kono
parents:
diff changeset
50 const struct s3 { int a; }; /* { dg-warning "14:useless type qualifier in empty declaration" } */
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 union u4;
kono
parents:
diff changeset
53 extern union u4 { int z; }; /* { dg-warning "14:useless storage class specifier in empty declaration" } */
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 enum e0 { E0 };
kono
parents:
diff changeset
56 void i(void) { const enum e0 { E1 }; } /* { dg-warning "32:useless type qualifier in empty declaration" } */
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 union u5 { int p; };
kono
parents:
diff changeset
59 void j(void) { extern struct u5 { int q; }; } /* { dg-warning "30:useless storage class specifier in empty declaration" } */