Consider following code:
#include <type_traits>
struct T {};
static_assert(std::is_trivially_destructible< T >{});
static_assert(std::is_trivially_default_constructible< T >{});
struct N { ~N() { ; } };
static_assert(!std::is_trivially_destructible< N >{});
static_assert(!std::is_trivially_default_constructible< N >{});
It compiles fine using clang 3.7.0
: live example. But summarizing the Standard:
The default constructor for class T is trivial (i.e. performs no action) if all of the following is true:
- The constructor is not user-provided (i.e., is implicitly-defined or defaulted)
- T has no virtual member functions
- T has no virtual base classes
- T has no non-static members with default initializers.
(since C++11)
- Every direct base of T has a trivial default constructor
- Every non-static member of class type has a trivial default constructor
As I can see there is no dependence on triviality of the destructor.
I missed something? Is it clang
bug?
ADDITIONAL
I found a workaround: is static_assert(__has_trivial_constructor( N ));
built-in type trait. There is support in clang
, gcc
and MSVC
.
For is_noexcept_constructible
family of type traits there is workaround too.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…