Author: marshall
Date: Wed Mar 15 13:41:11 2017
New Revision: 297872

URL: http://llvm.org/viewvc/llvm-project?rev=297872&view=rev
Log:
Implement LWG#2761: 'basic_string should require that charT match 
traits::char_type'. Tests for string_view, too

Added:
    libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp
    libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp
Removed:
    libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp
Modified:
    libcxx/trunk/include/string
    libcxx/trunk/include/string_view
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=297872&r1=297871&r2=297872&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Wed Mar 15 13:41:11 2017
@@ -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<allocator_type>             __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_type>::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<typename allocator_type::value_type, 
value_type>::value),
                   "Allocator::value_type must be same type as value_type");

Modified: libcxx/trunk/include/string_view
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=297872&r1=297871&r2=297872&view=diff
==============================================================================
--- libcxx/trunk/include/string_view (original)
+++ libcxx/trunk/include/string_view Wed Mar 15 13:41:11 2017
@@ -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_type>::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) {}

Added: libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp?rev=297872&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/traits_mismatch.fail.cpp Wed Mar 
15 13:41:11 2017
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+//   The strings's value type must be the same as the traits's char_type
+
+#include <string>
+
+int main()
+{
+    std::basic_string<char, std::char_traits<wchar_t>> s;
+}

Removed: libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp?rev=297871&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/string.view/nothing_to_do.pass.cpp (removed)
@@ -1,12 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     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.
-//
-//===----------------------------------------------------------------------===//
-
-#include <string_view>
-
-int main () {}

Added: libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp?rev=297872&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp (added)
+++ libcxx/trunk/test/std/strings/string.view/traits_mismatch.fail.cpp Wed Mar 
15 13:41:11 2017
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <string_view>
+//   The string_views's value type must be the same as the traits's char_type
+
+#include <string_view>
+
+int main()
+{
+    std::basic_string_view<char, std::char_traits<wchar_t>> s;
+}

Modified: libcxx/trunk/www/cxx1z_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=297872&r1=297871&r2=297872&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Wed Mar 15 13:41:11 2017
@@ -463,7 +463,7 @@
        <tr><td><a href="http://wg21.link/LWG2853";>2853</a></td><td>Possible 
inconsistency in specification of erase in 
[vector.modifiers]</td><td>Kona</td><td></td></tr>
        <tr><td><a 
href="http://wg21.link/LWG2855";>2855</a></td><td>std::throw_with_nested("string_literal")</td><td>Kona</td><td></td></tr>
        <tr><td><a 
href="http://wg21.link/LWG2857";>2857</a></td><td>{variant,optional,any}::emplace
 should return the constructed value</td><td>Kona</td><td></td></tr>
-       <tr><td><a 
href="http://wg21.link/LWG2861";>2861</a></td><td>basic_string should require 
that charT match traits::char_type</td><td>Kona</td><td></td></tr>
+       <tr><td><a 
href="http://wg21.link/LWG2861";>2861</a></td><td>basic_string should require 
that charT match traits::char_type</td><td>Kona</td><td>Clow</td></tr>
        <tr><td><a href="http://wg21.link/LWG2866";>2866</a></td><td>Incorrect 
derived classes constraints</td><td>Kona</td><td></td></tr>
        <tr><td><a href="http://wg21.link/LWG2868";>2868</a></td><td>Missing 
specification of bad_any_cast::what()</td><td>Kona</td><td>Complete</td></tr>
        <tr><td><a href="http://wg21.link/LWG2872";>2872</a></td><td>Add 
definition for 
direct-non-list-initialization</td><td>Kona</td><td>Complete</td></tr>


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to