llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Missing diagnostics for attributes after namespace name

Open MagentaTreehouse opened this issue 1 year ago • 4 comments

The location of the attribute is non-standard in this code:

namespace N [[deprecated]] {}

But clang doesn't emit any diagnostics with -Wall -Wextra -Wpedantic. Compiler Explorer: https://compiler-explorer.com/z/6zcPanj5Y

MagentaTreehouse avatar Dec 31 '24 18:12 MagentaTreehouse

CC @erichkeane

shafik avatar Dec 31 '24 22:12 shafik

named-namespace-definition: inline(opt) namespace attribute-specifier-seq(opt) identifier { namespace-body }

(namespace.def.general)

safocl avatar Jan 01 '25 13:01 safocl

The commit 8bd0055 added handling attributes after the namespace identifier.

Should attributes after the namespace be completely disallowed or just trigger a pedantic warning?

a-tarasyuk avatar Jan 02 '25 11:01 a-tarasyuk

The commit 8bd0055 added handling attributes after the namespace identifier.

Should attributes after the namespace be completely disallowed or just trigger a pedantic warning?

The key here is that we should diagnose attributes with the [[...]] spelling after the identifier. I believe this should just be an error (or not parsed), the way we would if we didn't try to parse it at all.

erichkeane avatar Jan 02 '25 15:01 erichkeane