From 4069c2bc483b31ba78075a42d939d97d9256e2fb Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 15 Mar 2017 18:41:11 +0000 Subject: [PATCH] Implement LWG#2761: 'basic_string should require that charT match traits::char_type'. Tests for string_view, too llvm-svn: 297872 --- libcxx/include/string | 4 ++-- libcxx/include/string_view | 4 ++++ .../basic.string/traits_mismatch.fail.cpp | 18 ++++++++++++++++++ ...to_do.pass.cpp => traits_mismatch.fail.cpp} | 8 +++++++- libcxx/www/cxx1z_status.html | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 libcxx/test/std/strings/basic.string/traits_mismatch.fail.cpp rename libcxx/test/std/strings/string.view/{nothing_to_do.pass.cpp => traits_mismatch.fail.cpp} (68%) diff --git a/libcxx/include/string b/libcxx/include/string index e1c64faf9e1c..714ff84dcb9d 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -637,7 +637,7 @@ public: typedef basic_string __self; typedef basic_string_view<_CharT, _Traits> __self_view; typedef _Traits traits_type; - typedef typename traits_type::char_type value_type; + typedef _CharT value_type; typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; @@ -648,7 +648,7 @@ public: typedef typename __alloc_traits::const_pointer const_pointer; static_assert(is_pod::value, "Character type of basic_string must be a POD"); - static_assert((is_same<_CharT, value_type>::value), + 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::value), "Allocator::value_type must be same type as value_type"); diff --git a/libcxx/include/string_view b/libcxx/include/string_view index 8be61328e8d4..5c42b36ca565 100644 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -199,6 +199,10 @@ public: typedef ptrdiff_t difference_type; static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); + static_assert(is_pod::value, "Character type of basic_string_view must be a POD"); + static_assert((is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + // [string.view.cons], construct/copy _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} diff --git a/libcxx/test/std/strings/basic.string/traits_mismatch.fail.cpp b/libcxx/test/std/strings/basic.string/traits_mismatch.fail.cpp new file mode 100644 index 000000000000..1d54238ae0c0 --- /dev/null +++ b/libcxx/test/std/strings/basic.string/traits_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// +// The strings's value type must be the same as the traits's char_type + +#include + +int main() +{ + std::basic_string> s; +} diff --git a/libcxx/test/std/strings/string.view/nothing_to_do.pass.cpp b/libcxx/test/std/strings/string.view/traits_mismatch.fail.cpp similarity index 68% rename from libcxx/test/std/strings/string.view/nothing_to_do.pass.cpp rename to libcxx/test/std/strings/string.view/traits_mismatch.fail.cpp index 353dd98f415e..6cd15e6a67ba 100644 --- a/libcxx/test/std/strings/string.view/nothing_to_do.pass.cpp +++ b/libcxx/test/std/strings/string.view/traits_mismatch.fail.cpp @@ -7,6 +7,12 @@ // //===----------------------------------------------------------------------===// +// +// The string_views's value type must be the same as the traits's char_type + #include -int main () {} +int main() +{ + std::basic_string_view> s; +} diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index cb6da83defdc..8a2939a3cac4 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -463,7 +463,7 @@ 2853Possible inconsistency in specification of erase in [vector.modifiers]Kona 2855std::throw_with_nested("string_literal")Kona 2857{variant,optional,any}::emplace should return the constructed valueKona - 2861basic_string should require that charT match traits::char_typeKona + 2861basic_string should require that charT match traits::char_typeKonaClow 2866Incorrect derived classes constraintsKona 2868Missing specification of bad_any_cast::what()KonaComplete 2872Add definition for direct-non-list-initializationKonaComplete