Search code examples
c++c++17language-lawyerc++20aggregate-initialization

Why is std::is_constructible not true for a trivial aggregate type?


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.


Solution

  • 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.