Date: Mon, 7 Jul 2025 19:37:59 +0200
On 07.07.25 17:41, Corentin via Core 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 <https://godbolt.org/z/Wj5fqdd1x>
Looks like ## should have the same divergence.
Jens
> https://eel.is/c++draft/lex.operators#1 <https://eel.is/c++draft/lex.operators#1>
> https://eel.is/c++draft/lex.token#nt:token <https://eel.is/c++draft/lex.token#nt:token>
> https://eel.is/c++draft/dcl.attr#nt:balanced-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
> 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 <https://godbolt.org/z/Wj5fqdd1x>
Looks like ## should have the same divergence.
Jens
> https://eel.is/c++draft/lex.operators#1 <https://eel.is/c++draft/lex.operators#1>
> https://eel.is/c++draft/lex.token#nt:token <https://eel.is/c++draft/lex.token#nt:token>
> https://eel.is/c++draft/dcl.attr#nt:balanced-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-07 17:38:03