Is std::is_standard_layout_v<T> always true if std::is_trivial_v<T> is true?

Viewed 180
template<typename T>
void f()
{
    if constexpr (std::is_trivial_v<T>)
    {
        // Does the following line never fail?
        static_assert(std::is_standard_layout_v<T>); 
    }
}
  1. Is std::is_standard_layout_v<T> always true if std::is_trivial_v<T> is true?

  2. If no, is there any counterexamples?

1 Answers
#include <type_traits>

class type
{
    public: int x;
    private: int y;
};

static_assert(std::is_trivial_v< type >);
// not standard layout because different access level of x and y
static_assert(not std::is_standard_layout_v< type >);

https://godbolt.org/z/xz3xLy

Related