================
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -ast-dump -std=c++17 %s | FileCheck %s
+
+// In C++, block-scope extern declarations target the enclosing namespace
+// scope ([dcl.meaning.general]/3.5), so they match against the namespace-scope
+// static despite local shadows and inherit internal linkage. No conflict 
arises.
+//
+// This differs from C, where a local shadow breaks linkage inheritance,
+// causing the conflict diagnosed by err_internal_extern_mismatch.
+
+// Example adapted from [basic.link]/6.
+static void f();
+// CHECK: FunctionDecl {{.*}} f 'void ()' static internal-linkage
+static int i = 0;
+// CHECK: VarDecl {{.*}} i 'int' static cinit internal-linkage
+void g() {
+// CHECK: FunctionDecl {{.*}} g 'void ()' external-linkage
+    extern void f();
+    // CHECK: FunctionDecl {{.*}} prev {{.*}} f 'void ()' extern 
internal-linkage
+    int i;
+    // CHECK: VarDecl {{.*}} i 'int'{{$}}
+    {
+        extern void f();
+        // CHECK: FunctionDecl {{.*}} prev {{.*}} f 'void ()' extern 
internal-linkage
+        extern int i;
+        // CHECK: VarDecl {{.*}} prev {{.*}} i 'int' extern internal-linkage
+    }
+}
+
+// Block-scope function declarations behave identically without extern
+// (C11 6.2.2p5, C++ [dcl.stc]p5).
----------------
flash1729 wrote:

my bad, I missed double-checking that one.

I think the correct citation is 
[**[dcl.meaning.general]/3.5**](https://eel.is/c++draft/dcl.meaning.general#3.5):

> If the declaration inhabits a block scope S and **declares a function** 
> ([dcl.fct]) **or uses the extern specifier**, the declaration shall not be 
> attached to a named module ([module.unit]); its target scope is the innermost 
> enclosing namespace scope, but the name is bound in S.

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