C++ Logo

liaison

Advanced search

[isocpp-wg14/wg21-liaison] Octothorpes in attributes: Divergence between C and C++

From: Corentin <corentin.jabot_at_[hidden]>
Date: Mon, 7 Jul 2025 17:41:38 +0200
Hey folks,

[[foo(#)]] is a valid attribute in C, but invalid in C++, as # is
considered a token in C and a preprocessing-operator in C++
(The grammar of attributes expects tokens in both languages)

Is this divergence intended? It does not seem desirable.

Note that there is implementation divergence amongst C++ compilers here,
Clang accepts in all language modes, GCC rejects in all language modes
https://godbolt.org/z/Wj5fqdd1x

Cheers!

https://eel.is/c++draft/lex.operators#1
https://eel.is/c++draft/lex.token#nt:token
https://eel.is/c++draft/dcl.attr#nt:balanced-token

Received on 2025-07-07 15:42:01