Author: Aaron Ballman Date: 2025-03-07T15:15:53-05:00 New Revision: 0ea02e77218d8aee37bc1a7c776caeeff468dc39
URL: https://github.com/llvm/llvm-project/commit/0ea02e77218d8aee37bc1a7c776caeeff468dc39 DIFF: https://github.com/llvm/llvm-project/commit/0ea02e77218d8aee37bc1a7c776caeeff468dc39.diff LOG: [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. Added: clang/test/C/C2y/n3410.c Modified: clang/www/c_status.html Removed: ################################################################################ diff --git a/clang/test/C/C2y/n3410.c b/clang/test/C/C2y/n3410.c new file mode 100644 index 0000000000000..e1cb41f375b82 --- /dev/null +++ b/clang/test/C/C2y/n3410.c @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wno-unused %s + +/* WG14 N3410: No + * Slay Some Earthly Demons XI + * + * It is now ill-formed for the same identifier within a TU to have both + * internal and external linkage. + */ + +void func1() { + extern int a; // #a +} + +// This 'a' is the same as the one declared extern above. +static int a; /* expected-error {{static declaration of 'a' follows non-static declaration}} + expected-note@#a {{previous declaration is here}} + */ + +static int b; +void func2() { + // This 'b' is the same as the one declaraed static above, but this is not + // ill-formed because of C2y 6.2.2p4, which gives this variable internal + // linkage because the previous declaration had internal linkage. + extern int b; // Ok +} + +static int c, d; +void func3() { + int c; // no linkage, diff erent object from the one declared above. + for (int d;;) { + // This 'c' is the same as the one declared at file scope, but because of + // the local scope 'c', the file scope 'c' is not visible. + // FIXME: This should be diagnosed under N3410. + extern int c; + // This 'd' is the same as the one declared at file scope as well, but + // because of the 'd' declared within the for loop, the file scope 'd' is + // also not visible, same as with 'c'. + // FIXME: This should be diagnosed under N3410. + extern int d; + } + for (static int e;;) { + extern int e; // Ok for the same reason as 'b' above. + } +} + diff --git a/clang/www/c_status.html b/clang/www/c_status.html index f9dc3a48654c7..1850bd2093e0c 100644 --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -289,7 +289,7 @@ <h2 id="c2y">C2y implementation status</h2> <tr> <td>Slay Some Earthly Demons XI</td> <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3410.pdf">N3410</a></td> - <td class="unknown" align="center">Unknown</td> + <td class="none" align="center">No</td> </tr> <tr> <td>Slay Some Earthly Demons XII</td> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits