std::is_assignable and abstract class

Viewed 55

Suppose you have an abstract class:

struct Abstr { virtual void f() = 0; };
static_assert(std::is_assignable<Abstr, Abstr>::value);

The assertion above fails with GCC (tested on version 10.3 and 11.2), but compiles just fine on Clang (tested on versions 12 and 13).

Also, with a custom implementation of the trait using concepts:

template <class T, class U>
concept is_assignable_concept = requires
{ std::declval<T>() = std::declval<U>(); };
static_assert(is_assignable_concept<Abstr, Abstr>);

the assertion never fails with either compiler.

What is the correct behavior here? Both are respected compilers, but I'm inclined to believe Clang is right here.

PD: I wonder why not use concepts to implement traits. At least in this case, it turns out to be much shorter than the sfinae version and with apparently correct behavior.

0 Answers
Related