From be0441cda16c2cb49d0bc3710d77912b866992a4 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 5 Sep 2020 08:53:39 +0700 Subject: [PATCH] enforce "non-array trivial standard-layout" for basic_string and basic_string_view (#1262) --- stl/inc/xstring | 8 ++++++++ tests/libcxx/expected_results.txt | 3 --- tests/libcxx/skipped_tests.txt | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index c61bef2cda..a1ac9f7590 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -1209,6 +1209,10 @@ public: "Bad char_traits for basic_string_view; " "N4659 24.4.2 [string.view.template]/1 \"the type traits::char_type shall name the same type as charT.\""); + static_assert(!is_array_v<_Elem> && is_trivial_v<_Elem> && is_standard_layout_v<_Elem>, + "The character type of basic_string_view must be a non-array trivial standard-layout type. See N4861 " + "[strings.general]/1."); + using traits_type = _Traits; using value_type = _Elem; using pointer = _Elem*; @@ -2290,6 +2294,10 @@ private: "N4659 24.3.2.1 [string.require]/3 requires that the supplied " "char_traits character type match the string's character type."); + static_assert(!is_array_v<_Elem> && is_trivial_v<_Elem> && is_standard_layout_v<_Elem>, + "The character type of basic_string must be a non-array trivial standard-layout type. See N4861 " + "[strings.general]/1."); + public: using traits_type = _Traits; using allocator_type = _Alloc; diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 1495b8c53e..594943c6ae 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -551,9 +551,6 @@ std/containers/sequences/array/array.data/data_const.pass.cpp FAIL std/containers/sequences/array/array.data/data.pass.cpp FAIL std/containers/sequences/array/iterators.pass.cpp FAIL -# STL bug: string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034. -std/strings/string.view/char.bad.fail.cpp:0 FAIL - # Predicate count assertions - IDL2 is slightly bending the Standard's rules here. std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp FAIL std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp FAIL diff --git a/tests/libcxx/skipped_tests.txt b/tests/libcxx/skipped_tests.txt index 8c47fea11e..2ad721b7ee 100644 --- a/tests/libcxx/skipped_tests.txt +++ b/tests/libcxx/skipped_tests.txt @@ -551,9 +551,6 @@ containers\sequences\array\array.data\data_const.pass.cpp containers\sequences\array\array.data\data.pass.cpp containers\sequences\array\iterators.pass.cpp -# STL bug: string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034. -strings\string.view\char.bad.fail.cpp - # Predicate count assertions - IDL2 is slightly bending the Standard's rules here. algorithms\alg.sorting\alg.heap.operations\make.heap\make_heap_comp.pass.cpp algorithms\alg.sorting\alg.merge\inplace_merge_comp.pass.cpp