Skip to content

Commit 0ea02e7

Browse files
committed
[C2y] Claim nonconformance to WG14 N3410
This paper made it a constraint violation for the same identifier within a TU to have both internal and external linkage. It was previously UB. Clang does not correctly diagnose the constraint in some cases, documented in the added test case.
1 parent b0baa1d commit 0ea02e7

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

clang/test/C/C2y/n3410.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+

clang/www/c_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ <h2 id="c2y">C2y implementation status</h2>
289289
<tr>
290290
<td>Slay Some Earthly Demons XI</td>
291291
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3410.pdf">N3410</a></td>
292-
<td class="unknown" align="center">Unknown</td>
292+
<td class="none" align="center">No</td>
293293
</tr>
294294
<tr>
295295
<td>Slay Some Earthly Demons XII</td>

0 commit comments

Comments
 (0)