Date: Wed, 9 Jul 2025 12:30:00 -0700
On Mon, 7 Jul 2025 at 08:42, Corentin via Core <core_at_[hidden]>
wrote:
> 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
>
I think we reach [lex.phases]/7's "Each preprocessing token is converted
into a token ([lex.token]).", which doesn't give any allowance for
producing a diagnostic or similar, so this looks to me like a "behavior is
implicitly undefined during translation" situation!
The suggested wording for CWG1901 would at least fix that, but as it stands
it would also clarify that [[foo(#)]] is ill-formed.
> 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
> _______________________________________________
> Core mailing list
> Core_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
> Link to this post: http://lists.isocpp.org/core/2025/07/18326.php
>
wrote:
> 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
>
I think we reach [lex.phases]/7's "Each preprocessing token is converted
into a token ([lex.token]).", which doesn't give any allowance for
producing a diagnostic or similar, so this looks to me like a "behavior is
implicitly undefined during translation" situation!
The suggested wording for CWG1901 would at least fix that, but as it stands
it would also clarify that [[foo(#)]] is ill-formed.
> 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
> _______________________________________________
> Core mailing list
> Core_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
> Link to this post: http://lists.isocpp.org/core/2025/07/18326.php
>
Received on 2025-07-09 19:30:15