C++ Logo

liaison

Advanced search

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

From: Jens Gustedt <jens.gustedt_at_[hidden]>
Date: Wed, 09 Jul 2025 20:49:43 +0200
Hi,

Am 9. Juli 2025 20:15:57 MESZ schrieb Corentin via Liaison <liaison_at_[hidden]>:
> On Mon, Jul 7, 2025 at 7:38 PM Jens Maurer <jens.maurer_at_[hidden]> wrote:
>
> >
> >
> > 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.
> >
>
> yes, the same question applies to all of #, ##, %:, %:%:

Actually to all preprocessor tokens, that have no equivalent
in translation phase 7. these are probably a lot more than the ones
listed.

Jens G
>
>
> >
> > 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
> >
> >


-- 
Jens Gustedt - INRIA & ICube, Strasbourg, France 

Received on 2025-07-09 18:49:49