Home > Mobile >  Can a concept be declared deprecated?
Can a concept be declared deprecated?

Time:01-07

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?

CodePudding user response:

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.

CodePudding user response:

I haven't found a way to make make the attribute work directly on the concept but you can add it to the implementation:

template<class T>
struct someBoolCondition_impl {
    // needed for clang/msvc:
    [[deprecated ("Some explanation")]] static constexpr bool value = true;
};

template<class T>
// needed for gcc:
[[deprecated ("Some explanation")]] 
inline constexpr bool someBoolCondition = someBoolCondition_impl<T>::value;

template <class T>
concept myConcept = someBoolCondition<T>;

Demo

  • Related