Search code examples
c++c++20c++-conceptsdeprecation-warning

Can a concept be declared deprecated?


I just encountered a case where I wanted to declare a C++ 20 concept deprecated. However it seems like my compiler (Apple Clang 14) does not accept adding a [[deprecated]] attribute to a concept. My attempt looked like

template <class T>
concept [[deprecated ("Some explanation")]] myConcept = someBoolCondition<T>;

Is deprecating concepts simply not supported (yet), did I choose a wrong syntax or is this a flaw of my compiler?


Solution

  • The possibility to add [[deprecated]] to a concept definition has been added only recently as a defect report with resolution of CWG 2428.

    However, the attribute belongs after the concept's name, not before it:

    template <class T>
    concept myConcept [[deprecated ("Some explanation")]] = someBoolCondition<T>;
    

    Your compiler is older than the resolution, so it can't have implemented it yet. It seems Clang hasn't implemented it yet at all, but future versions probably will.

    GCC trunk does implement the DR, so the next GCC release (version 13), probably will as well.

    Latest MSVC does not seem to implement it yet.