[clang] [Clang] disallow selectany on non-global-variable declarations (PR #189641)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Fri May 8 04:35:48 PDT 2026


mstorsjo wrote:

> > I think the main key word is external linkage in any case.
> 
> But then wouldn't it be accepted on:
> 
> ```
> struct T {
>   SA static int i;
> };
> ```
> 
> because that still has external linkage: https://godbolt.org/z/vafPxa4jh ?

Right, I guess. In that sense it feels like it boils down to the distinction between declaration and definition. But for regular extern variables, we do accept selectany on a pure declaration, and MSVC also accepts that. While selectany shouldn't make any difference for a consumer of the declaration, it only makes a difference for the definition.

I guess I don't know which language level nuance should be used for distinguishing these cases then... But IMO it needs to be possible to set this attribute on any definition of a symbol with external linkage. Setting it on a declaration of such symbols isn't strictly needed but perhaps is accepted for other reasons.

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


More information about the cfe-commits mailing list