Debian Codegraph @

clang/test/C/C2y/n3410.c

raw
1 // RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wno-unused %s
2
3 /* WG14 N3410: No
4 * Slay Some Earthly Demons XI
5 *
6 * It is now ill-formed for the same identifier within a TU to have both
7 * internal and external linkage.
8 */
9
10 void func1() {
11 extern int a; // #a
12 }
13
14 // This 'a' is the same as the one declared extern above.
15 static int a; /* expected-error {{static declaration of 'a' follows non-static declaration}}
16 expected-note@#a {{previous declaration is here}}
17 */
18
19 static int b;
20 void func2() {
21 // This 'b' is the same as the one declaraed static above, but this is not
22 // ill-formed because of C2y 6.2.2p4, which gives this variable internal
23 // linkage because the previous declaration had internal linkage.
24 extern int b; // Ok
25 }
26
27 static int c, d;
28 void func3() {
29 int c; // no linkage, different object from the one declared above.
30 for (int d;;) {
31 // This 'c' is the same as the one declared at file scope, but because of
32 // the local scope 'c', the file scope 'c' is not visible.
33 // FIXME: This should be diagnosed under N3410.
34 extern int c;
35 // This 'd' is the same as the one declared at file scope as well, but
36 // because of the 'd' declared within the for loop, the file scope 'd' is
37 // also not visible, same as with 'c'.
38 // FIXME: This should be diagnosed under N3410.
39 extern int d;
40 }
41 for (static int e;;) {
42 extern int e; // Ok for the same reason as 'b' above.
43 }
44 }
45