[clang] [Clang] Diagnose UB and emit error when identifier has both internal and external linkage (PR #192116)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 06:44:24 PDT 2026
================
@@ -6528,6 +6528,9 @@ def err_inline_declaration_block_scope : Error<
"inline declaration of %0 not allowed in block scope">;
def err_static_non_static : Error<
"static declaration of %0 follows non-static declaration">;
+def err_internal_extern_mismatch : Error<
+ "variable %0 declared with both internal and external linkage "
+ "in the same translation unit; behavior is undefined">;
----------------
AaronBallman wrote:
```suggestion
"in the same translation unit%select{; behavior is undefined|}0">;
```
I think we want to drop "; behavior is undefined" when in C2y mode.
Hopefully this being a hard error is not disruptive in practice. I don't expect it to be, but if it is, we may want to turn this into a warning which defaults to an error so users can get the old behavior back.
https://github.com/llvm/llvm-project/pull/192116
More information about the cfe-commits
mailing list