C++ Logo

std-discussion

Advanced search

No attributes for concepts in C++20

From: Jean Guegant <jguegant_at_[hidden]>
Date: Tue, 15 Sep 2020 16:23:18 +0200
Hello everyone,

I recently noticed that there is no way to attach C++ attributes to
concepts introduced in C++20. More precisely, the C++ grammar doesn't have
any placeholder for starting an attribute specifier sequence
<https://eel.is/c++draft/dcl.attr#nt:attribute-specifier-seq>. In practice,
this means that you cannot deprecate a concept using the [[deprecated]]
attribute introduced in C++14 for instance. It also means that you cannot
really extend that new C++ feature using custom attributes. Apparently this
limitation of the language has been discovered by other people and it feels
that this could have been an oversight from the committee when integrating
concepts to the language.

I was considering to report this problem as a standard issue but I would
like to seek
advice here first:

   - Firstly, was there any reason that I missed to not add attributes to
   concepts?
   - Secondly, if this was not considered at the time of designing
   concepts, is that sufficiently important to escalate it as an issue rather
   than a proposal for C++23? It feels to me that this should have been part
   of C++20 and is quite unexpected. Clang even has special error handling (
   here
   <https://github.com/llvm/llvm-project/blob/ce6dd973ac556a326c38bd7667b4fb448f215d09/clang/lib/Parse/ParseTemplate.cpp#L370>
   and here
   <https://github.com/llvm/llvm-project/blob/ce6dd973ac556a326c38bd7667b4fb448f215d09/clang/lib/Parse/ParseTemplate.cpp#L407>)
   to help people trying to use attributes with concepts. This clearly
   highlights that users assume that attributes should work somehow with
   concepts.
   - Finally, if I go for an issue or a proposal, what would be the best
   place to introduce the attribute specifier sequence? Depending on how we
   think of concepts, the 3 following notations look possible to me:
      - template <class T> [[here]] concept bla = ...; - akin to
      attributes for variables or class/struct)
      - template <class T> concept [[here]] bla = ...; - akin to attributes
      for class/struct
      - template <class T> concept bla [[here]] = ...; - akin to
      attributes for alias templates


I would really appreciate some help here.

Sincerely,
Jean Guegant

Received on 2020-09-15 09:23:32