C++ Logo

sg15

Advanced search

Re: Supporting User-Defined Attributes

From: Corentin Jabot <corentinjabot_at_[hidden]>
Date: Tue, 22 Mar 2022 09:13:59 +0100
Hey
I'd like to point out https://wg21.link/p1887r1 - Reflection on attributes
which have a different goal (being able to reflect on user defined
attributes), but a similar conclusion:
attributes would be in general that much more usable if they were declared
before being used.

My approach at the time (this is not something I'm currently actively
pursuing as reflection has not progressed) was to use defined attributes as
good old c++ structs with a constexpr constructor,
which allow for different overloads and can do some validation - without
adding new syntax.

I don't know if you would find this approach suitable, but maybe we can
converge on a solution.

Alas, because of the whole "attribute can be ignored even if compilers warn
on unknown attribute" thing, it's likely that people will want a new
syntax...
This is the feedback I got at the time anyway.


struct my_attr {};
[[my_atr()]] void foo(); // typo or other attribute that should be ignored?
[[+my_atr()]] void foo(); // some kind of sigil might be necessary.


Have a great day,
Corentin


On Wed, Mar 16, 2022 at 2:48 AM Bret Brown via SG15 <sg15_at_[hidden]>
wrote:

> Hi all!
>
> It's interesting that all the tools I've looked at have a hard time
> distinguishing between misspellings of attributes and user-defined
> attributes.
>
> Given that, and the need to keep the SG15 backlog populated, I have marked
> a paper on the subject for review, though I believe I just missed the
> filing deadline. It might be officially published in the April mailing.
>
> Here is the paper: https://isocpp.org/files/papers/P2565R0.pdf
>
> Here is the abstract:
>
> While the standard supports vendor-provided and otherwise user-defined
> attributes in C++, actual use of nonstandard attributes while preventing
> trivial misspellings is a challenge. In particular, diagnostics in
> compilers used to prevent misspellings of standard and well-known
> attributes will reject attributes provided for other contexts, including
> attributes used to support other compilers. This document explores how this
> problem presents itself in practice and proposes a potential attribute
> declaration syntax to address the problem.
>
>
> Regards,
> Bret Brown
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15
>

Received on 2022-03-22 08:14:11