In regards to C 17; GCC, Clang, and MSVC consider a trival class type not to be constructible by any of its data member types. Since C 20, GCC and MSVC changed this, allowing the example below to compile.
#include <type_traits>
struct t {
int a;
};
static_assert(std::is_constructible<t, int>{});
Unfortunately, Clang seems to disagree and rejects this code when compiling with -std=c 20
as well. Is this a compiler bug of Clang? And why do all compilers not consider a type like t
to be constructible with an int
when compiling with -std=c 17
? After all, t{0}
seems to be pretty constructible that way.
CodePudding user response:
Constructibility is based on the ability to use constructor syntax (T(values)
). In C 20, aggregates can be initialized using constructor syntax, but in C 17 and before, they must use {}
syntax.
Clang's C 20 implementation is simply not up to the standard yet.
CodePudding user response:
Clang will compile this if you add a constructor that can construct a t
from an int
. I'm not sure why this would not work without it in clang.