================
@@ -1,45 +1,99 @@
-// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c2y -std=c2y -Wall -pedantic -Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c89-23 -std=c23 -Wall -pedantic 
-Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c89-23 -std=c17 -Wall -pedantic 
-Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c89-23 -std=c11 -Wall -pedantic 
-Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c89-23 -std=c99 -Wall -pedantic 
-Wno-unused %s
+// RUN: %clang_cc1 -verify=expected,c89-23 -std=c89 -Wall -pedantic 
-Wno-unused -Wno-comment %s
 
-/* WG14 N3410: No
+/* WG14 N3410: Clang 24
  * 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
+void func1(void) {
+  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}}
+/* This 'a' is the same as the one declared extern above. */
+static int a; /* c2y-error {{static declaration of 'a' follows non-static 
declaration}}
+                 c89-23-error {{static declaration of 'a' follows non-static 
declaration; behavior is undefined}}
                  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
+void func2(void) {
+  /* This 'b' is well-formed, because C2y 6.2.2p6 makes it "inherit" the
+     static linkage of `static int b` above, because the latter is visible.
+   */
+  extern int b; /* Ok */
 }
 
-static int c, d;
-void func3() {
-  int c; // no linkage, different 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;
+static int c, d; /* expected-note 2 {{previous definition is here}} */
+void func3(void) {
+  int c; /* no linkage, different object from the one declared above. */
+  {
+    int d; /* no linkage, different object from the file-scope '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. */
+      extern int c; /* c2y-error {{variable 'c' cannot be declared with 
external linkage following a declaration with internal linkage}}
----------------
AaronBallman wrote:

Here's an additional test case; I suspect we're going to get surprising (but 
correct) diagnostic behavior, but I think it's fine to have a FIXME comment 
saying it would be nice to improve the behavior:
```
static int c;

int main() {
  {
    extern int c; // note: lol, surprise, this has internal linkage
  }

  int c;
  
  {
    extern int c; // error: cannot be declared extern following internal 
  }
}
```
We can address the usability issue if a user ever hits the problem, which I 
would be surprised if they did because you have to work at it.

https://github.com/llvm/llvm-project/pull/193567
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to