C++ Logo

liaison

Advanced search

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

From: Aaron Ballman <aaron_at_[hidden]>
Date: Wed, 30 Jul 2025 19:15:14 +0000
My preference is to allow # in an attribute argument list, same as in
C. Making it ill-formed removes design space from implementers in a
feature designed specifically for implementers to use for their own
needs. So if WG21 thinks they want to make # do something outside of
the preprocessor, that's a good reason to make it ill-formed to use in
an attribute argument list. But otherwise this closes the door on
useful argument lists. e.g., accepting text that isn't valid C++ at
all, such as HTML code which uses # in color codes.

(Note, I don't think the preprocessor needs to be aware of attributes
so that it can handle # in attribute argument lists in a special way.
I only think that, after preprocessing, if a # remains in the token
stream, that should not be ill-formed within an attribute argument
list.)

~Aaron

On Mon, Jul 7, 2025 at 3:41 PM 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
>
> 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-30 19:15:28