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