[clang] [clang] emit an error when the same identifier appears with both internal and external linkage in a translation unit (PR #78064)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 28 12:47:56 PST 2024


================
@@ -4754,6 +4754,11 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
     return New->setInvalidDecl();
   }
 
+  if (Old->getFormalLinkage() != New->getFormalLinkage()) {
+    Diag(New->getLocation(), diag::err_multiple_linkage) << New->getDeclName();
+    return New->setInvalidDecl();
+  }
----------------
elhewaty wrote:

@AaronBallman
> If the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration.

Then when should the declaration be an issue (https://godbolt.org/z/roE9xh76d)?
[Note: the diagnostic of clang and GCC is different.]
If the external linkage follows the previous linkage, when could the error happen?




https://github.com/llvm/llvm-project/pull/78064


More information about the cfe-commits mailing list