In the following exemple the first static assertion fired but not the second:
#include<type_traits>
struct A{
protected:
~A()=default;
};
struct B:A{
//this static assertion fails
static_assert(std::is_trivially_destructible<A>::value,"");
};
//this static assertion succeeds
static_assert(std::is_trivially_destructible<B>::value,"");
(checked with GCC,Clang,MSVC,ellcc)
I don't understand why A can not be trivially_destructible, inside B, while B is trivially destructible. This seems to be in contradiction with these 2 paragraphs of the C++ standard, where accessibility is not mentionned:
[class.dtor]
A destructor is trivial if it is not user-provided and if:
(6.1) — the destructor is not
virtual
,(6.2) — all of the direct base classes of its class have trivial destructors, and
(6.3) — for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.
[dcl.fct.def.default]
A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration.
Aucun commentaire:
Enregistrer un commentaire