C++ Logo

liaison

Advanced search

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

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Wed, 9 Jul 2025 23:47:54 +0200
On 09.07.25 21:30, Richard Smith via Liaison wrote:
> On Mon, 7 Jul 2025 at 08:42, Corentin via Core <core_at_[hidden] <mailto: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 <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.

CWG1901 https://cplusplus.github.io/CWG/issues/1901.html
needs a serious rebase; the current Working Draft no longer mentions "punctuators"
(follow the links in the issue write-up).

This was fixed by

    NB US 028 (C++20 CD): Define grammar for "punctuator"

https://github.com/cplusplus/draft/commit/c2bc025f8f781a2c917880eacc011375423003a9

Jens

Received on 2025-07-09 21:48:02