Skip to content

Commit be0441c

Browse files
authored
enforce "non-array trivial standard-layout" for basic_string and basic_string_view (#1262)
1 parent 4f72f78 commit be0441c

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

stl/inc/xstring

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,10 @@ public:
12091209
"Bad char_traits for basic_string_view; "
12101210
"N4659 24.4.2 [string.view.template]/1 \"the type traits::char_type shall name the same type as charT.\"");
12111211

1212+
static_assert(!is_array_v<_Elem> && is_trivial_v<_Elem> && is_standard_layout_v<_Elem>,
1213+
"The character type of basic_string_view must be a non-array trivial standard-layout type. See N4861 "
1214+
"[strings.general]/1.");
1215+
12121216
using traits_type = _Traits;
12131217
using value_type = _Elem;
12141218
using pointer = _Elem*;
@@ -2290,6 +2294,10 @@ private:
22902294
"N4659 24.3.2.1 [string.require]/3 requires that the supplied "
22912295
"char_traits character type match the string's character type.");
22922296

2297+
static_assert(!is_array_v<_Elem> && is_trivial_v<_Elem> && is_standard_layout_v<_Elem>,
2298+
"The character type of basic_string must be a non-array trivial standard-layout type. See N4861 "
2299+
"[strings.general]/1.");
2300+
22932301
public:
22942302
using traits_type = _Traits;
22952303
using allocator_type = _Alloc;

tests/libcxx/expected_results.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,6 @@ std/containers/sequences/array/array.data/data_const.pass.cpp FAIL
551551
std/containers/sequences/array/array.data/data.pass.cpp FAIL
552552
std/containers/sequences/array/iterators.pass.cpp FAIL
553553

554-
# STL bug: string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034.
555-
std/strings/string.view/char.bad.fail.cpp:0 FAIL
556-
557554
# Predicate count assertions - IDL2 is slightly bending the Standard's rules here.
558555
std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp FAIL
559556
std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp FAIL

tests/libcxx/skipped_tests.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,6 @@ containers\sequences\array\array.data\data_const.pass.cpp
551551
containers\sequences\array\array.data\data.pass.cpp
552552
containers\sequences\array\iterators.pass.cpp
553553

554-
# STL bug: string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034.
555-
strings\string.view\char.bad.fail.cpp
556-
557554
# Predicate count assertions - IDL2 is slightly bending the Standard's rules here.
558555
algorithms\alg.sorting\alg.heap.operations\make.heap\make_heap_comp.pass.cpp
559556
algorithms\alg.sorting\alg.merge\inplace_merge_comp.pass.cpp

0 commit comments

Comments
 (0)