annotate gcc/testsuite/gcc.dg/redecl-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test for various situations where a new declaration of an
kono
parents:
diff changeset
2 identifier conflicts with an earlier declaration which isn't in the
kono
parents:
diff changeset
3 same scope. These are all undefined behavior per C89 sections
kono
parents:
diff changeset
4 6.1.2.2p7, 6.1.2.6p2, and 6.3.2.2p2/footnote 38 (C99 6.2.2p7 and
kono
parents:
diff changeset
5 6.2.7p2 - implicit declarations are invalid in C99). */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 /* { dg-do compile } */
kono
parents:
diff changeset
8 /* { dg-options "-std=c89 -pedantic -Wall -Wno-unused" } */
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 /* Extern at function scope, clashing with extern at file scope */
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 extern int foo1; /* { dg-message "note: previous" } */
kono
parents:
diff changeset
13 extern int bar1(int); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 void test1(void)
kono
parents:
diff changeset
16 {
kono
parents:
diff changeset
17 extern double foo1; /* { dg-error "conflict" } */
kono
parents:
diff changeset
18 extern double bar1(double); /* { dg-error "conflict" } */
kono
parents:
diff changeset
19 }
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* Extern at file scope, clashing with extern at function scope */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 void test2(void)
kono
parents:
diff changeset
24 {
kono
parents:
diff changeset
25 extern double foo2; /* { dg-message "note: previous" } */
kono
parents:
diff changeset
26 extern double bar2(double); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
27 }
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 extern int foo2; /* { dg-error "conflict" } */
kono
parents:
diff changeset
30 extern int bar2(int); /* { dg-error "conflict" } */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 /* Extern at function scope, clashing with extern at earlier function
kono
parents:
diff changeset
33 scope. Also, don't be fooled by a typedef at file scope. */
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 typedef float baz3; /* { dg-bogus } */
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 void prime3(void)
kono
parents:
diff changeset
38 {
kono
parents:
diff changeset
39 extern int foo3; /* { dg-message "note: previous" } */
kono
parents:
diff changeset
40 extern int bar3(int); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
41 extern int baz3; /* { dg-message "note: previous" } */
kono
parents:
diff changeset
42 }
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 void test3(void)
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 extern double foo3; /* { dg-error "conflict" } */
kono
parents:
diff changeset
47 extern double bar3(double); /* { dg-error "conflict" } */
kono
parents:
diff changeset
48 extern double baz3; /* { dg-error "conflict" } */
kono
parents:
diff changeset
49 }
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* Extern at function scope, clashing with previous implicit decl. */
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 void prime4(void)
kono
parents:
diff changeset
54 {
kono
parents:
diff changeset
55 bar4(); /* { dg-line implicit_bar4 } */
kono
parents:
diff changeset
56 /* { dg-warning "implicit declaration of function" "implicit" { target *-*-* } implicit_bar4 } */
kono
parents:
diff changeset
57 }
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 void test4(void)
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 extern double bar4(double); /* { dg-error "conflict" } */
kono
parents:
diff changeset
62 /* { dg-message "note: previous implicit declaration" "previous" { target *-*-* } implicit_bar4 } */
kono
parents:
diff changeset
63 }
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /* Implicit decl, clashing with extern at previous function scope. */
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 void prime5(void)
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 extern double bar5(double); /* { dg-message "note: previous declaration" "previous 1" } */
kono
parents:
diff changeset
70 } /* { dg-message "note: previous implicit declaration" "previous 2" { target *-*-* } .-1 } */
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 void test5(void)
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 bar5(1); /* { dg-warning "implicit declaration of function" } */
kono
parents:
diff changeset
75 } /* { dg-error "incompatible implicit declaration" "" { target *-*-* } .-1 } */
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* Extern then static, both at file scope. */
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 extern int test6(int); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
80 static int test6(int x) /* { dg-error "follows non-static" } */
kono
parents:
diff changeset
81 { return x; }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* Extern then static, extern at previous function scope. */
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 void prime7(void)
kono
parents:
diff changeset
87 {
kono
parents:
diff changeset
88 extern int test7(int); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
89 }
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 static int test7(int x) /* { dg-error "follows non-static" } */
kono
parents:
diff changeset
92 { return x; }
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* Implicit decl then static. */
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 void prime8(void)
kono
parents:
diff changeset
97 {
kono
parents:
diff changeset
98 test8(); /* { dg-message "note: previous" } */
kono
parents:
diff changeset
99 /* { dg-warning "implicit" "implicit" { target *-*-* } .-1 } */
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 static int test8(int x) /* { dg-error "follows non-static" } */
kono
parents:
diff changeset
103 { return x; }