Implement LWG3034: P0767R1 breaks previously-standard-layout types

llvm-svn: 328064
This commit is contained in:
Marshall Clow 2018-03-21 00:36:05 +00:00
parent 1c1057af0b
commit 4a6f3c4710
9 changed files with 192 additions and 11 deletions

View File

@ -658,10 +658,12 @@ public:
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
static_assert(is_trivial<value_type>::value, "Character type of basic_string must be trivial");
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
#if defined(_LIBCPP_RAW_ITERATORS)
typedef pointer iterator;

View File

@ -208,7 +208,9 @@ public:
typedef ptrdiff_t difference_type;
static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
static_assert(is_trivial<value_type>::value, "Character type of basic_string_view must be trivial");
static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");

View File

@ -48,6 +48,8 @@ int main()
// P0767
static_assert(std::is_trivial<max_align_t>::value,
"std::is_trivial<max_align_t>::value");
static_assert(std::is_standard_layout<max_align_t>::value,
"std::is_standard_layout<max_align_t>::value");
#else
static_assert(std::is_pod<max_align_t>::value,
"std::is_pod<max_align_t>::value");

View File

@ -10,18 +10,21 @@
#include <cstddef>
#include <type_traits>
// max_align_t is a POD type whose alignment requirement is at least as
// great as that of every scalar type
// max_align_t is a trivial standard-layout type whose alignment requirement
// is at least as great as that of every scalar type
#include <stdio.h>
#include "test_macros.h"
int main()
{
#if TEST_STD_VER > 17
// P0767
static_assert(std::is_trivial<std::max_align_t>::value,
"std::is_trivial<std::max_align_t>::value");
static_assert(std::is_standard_layout<std::max_align_t>::value,
"std::is_standard_layout<std::max_align_t>::value");
#else
static_assert(std::is_pod<std::max_align_t>::value,
"std::is_pod<std::max_align_t>::value");

View File

@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <string>
// ... manipulating sequences of any non-array trivial standard-layout types.
#include <string>
#include "test_traits.h"
struct NotTrivial {
NotTrivial() : value(3) {}
int value;
};
struct NotStandardLayout {
public:
NotStandardLayout() : one(1), two(2) {}
int sum() const { return one + two; } // silences "unused field 'two' warning"
int one;
private:
int two;
};
int main()
{
{
// array
typedef char C[3];
static_assert(std::is_array<C>::value, "");
std::basic_string<C, test_traits<C> > s;
// expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must not be an array"}}
}
{
// not trivial
static_assert(!std::is_trivial<NotTrivial>::value, "");
std::basic_string<NotTrivial, test_traits<NotTrivial> > s;
// expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be trivial"}}
}
{
// not standard layout
static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
std::basic_string<NotStandardLayout, test_traits<NotStandardLayout> > s;
// expected-error-re@string:* {{static_assert failed{{.*}} "Character type of basic_string must be standard-layout"}}
}
}

View File

@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <string_view>
// ... manipulating sequences of any non-array trivial standard-layout types.
#include <string>
#include "../basic.string/test_traits.h"
struct NotTrivial {
NotTrivial() : value(3) {}
int value;
};
struct NotStandardLayout {
public:
NotStandardLayout() : one(1), two(2) {}
int sum() const { return one + two; } // silences "unused field 'two' warning"
int one;
private:
int two;
};
int main()
{
{
// array
typedef char C[3];
static_assert(std::is_array<C>::value, "");
std::basic_string_view<C, test_traits<C> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must not be an array"}}
}
{
// not trivial
static_assert(!std::is_trivial<NotTrivial>::value, "");
std::basic_string_view<NotTrivial, test_traits<NotTrivial> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be trivial"}}
}
{
// not standard layout
static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be standard-layout"}}
}
}

View File

@ -10,6 +10,9 @@
// type_traits
// aligned_storage
//
// Issue 3034 added:
// The member typedef type shall be a trivial standard-layout type.
#include <type_traits>
#include <cstddef> // for std::max_align_t
@ -28,6 +31,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 1, "");
static_assert(sizeof(T1) == 10, "");
}
@ -42,6 +47,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 10, "");
}
@ -56,6 +63,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 12, "");
}
@ -70,6 +79,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}
@ -84,6 +95,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 16, "");
}
@ -98,6 +111,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 32, "");
}
@ -112,6 +127,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 32, "");
}
@ -126,6 +143,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 32, "");
static_assert(sizeof(T1) == 64, "");
}
@ -140,6 +159,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 16, "");
static_assert(sizeof(T1) == 16, "");
}
@ -154,6 +175,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 1, "");
static_assert(sizeof(T1) == 1, "");
}
@ -168,6 +191,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 2, "");
}
@ -182,6 +207,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 4, "");
}
@ -196,6 +223,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 4, "");
}
@ -210,6 +239,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 8, "");
}
@ -218,6 +249,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 8, "");
}
@ -232,6 +265,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 8, "");
}
@ -246,6 +281,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}
@ -260,6 +297,8 @@ int main()
#else
static_assert(std::is_pod<T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}
@ -274,6 +313,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
"");
static_assert(sizeof(T1) == 16, "");
@ -283,6 +324,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
"");
static_assert(sizeof(T1) == 16 + alignof(std::max_align_t), "");
@ -292,6 +335,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}

View File

@ -13,6 +13,9 @@
// aligned_union<size_t Len, class ...Types>
// Issue 3034 added:
// The member typedef type shall be a trivial standard-layout type.
#include <type_traits>
#include "test_macros.h"
@ -24,6 +27,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, char>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 1, "");
static_assert(sizeof(T1) == 10, "");
}
@ -32,6 +37,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, short>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 10, "");
}
@ -40,6 +47,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, int>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 12, "");
}
@ -48,6 +57,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, double>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 8, "");
static_assert(sizeof(T1) == 16, "");
}
@ -56,6 +67,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, short, char>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 10, "");
}
@ -64,6 +77,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<10, char, short>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 2, "");
static_assert(sizeof(T1) == 10, "");
}
@ -72,6 +87,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<2, int, char, short>, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 4, "");
}
@ -80,6 +97,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<2, char, int, short >, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 4, "");
}
@ -88,6 +107,8 @@ int main()
#if TEST_STD_VER > 11
static_assert(std::is_same<std::aligned_union_t<2, char, short, int >, T1>::value, "" );
#endif
static_assert(std::is_trivial<T1>::value, "");
static_assert(std::is_standard_layout<T1>::value, "");
static_assert(std::alignment_of<T1>::value == 4, "");
static_assert(sizeof(T1) == 4, "");
}

View File

@ -166,10 +166,10 @@
<tr><td><a href="https://wg21.link/LWG3020">3020</a></td><td>[networking.ts] Remove spurious nested <tt>value_type</tt> buffer sequence requirement</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3026">3026</a></td><td><tt>filesystem::weakly_canonical</tt> still defined in terms of <tt>canonical(p, base)</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3030">3030</a></td><td>Who shall meet the requirements of <tt>try_lock</tt>?</td><td>Jacksonville</td><td><i>Nothing to do</i></td></tr>
<tr><td><a href="https://wg21.link/LWG3034">3034</a></td><td>P0767R1 breaks previously-standard-layout types</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3035">3035</a></td><td><tt>std::allocator</tt>'s constructors should be <tt>constexpr</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3039">3039</a></td><td>Unnecessary <tt>decay</tt> in <tt>thread</tt> and <tt>packaged_task</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3041">3041</a></td><td>Unnecessary <tt>decay</tt> in <tt>reference_wrapper</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3034">3034</a></td><td>P0767R1 breaks previously-standard-layout types</td><td>Jacksonville</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3035">3035</a></td><td><tt>std::allocator</tt>'s constructors should be <tt>constexpr</tt></td><td>Jacksonville</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3039">3039</a></td><td>Unnecessary <tt>decay</tt> in <tt>thread</tt> and <tt>packaged_task</tt></td><td>Jacksonville</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3041">3041</a></td><td>Unnecessary <tt>decay</tt> in <tt>reference_wrapper</tt></td><td>Jacksonville</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3042">3042</a></td><td><tt>is_literal_type_v</tt> should be inline</td><td>Jacksonville</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3043">3043</a></td><td>Bogus postcondition for <tt>filesystem_error</tt> constructor</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3045">3045</a></td><td><tt>atomic&lt;<i>floating-point</i>&gt;</tt> doesn't have <tt>value_type</tt> or <tt>difference_type</tt></td><td>Jacksonville</td><td></td></tr>
@ -180,7 +180,7 @@
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
</table>
<p>Last Updated: 18-Mar-2018</p>
<p>Last Updated: 20-Mar-2018</p>
</div>
</body>
</html>