[libcxx-commits] [libcxx] r364842 - Ensure bitset's string constructor doesn't poison the overload set.

Eric Fiselier via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 1 12:59:34 PDT 2019


Author: ericwf
Date: Mon Jul  1 12:59:34 2019
New Revision: 364842

URL: http://llvm.org/viewvc/llvm-project?rev=364842&view=rev
Log:
Ensure bitset's string constructor doesn't poison the overload set.

Modified:
    libcxx/trunk/include/bitset
    libcxx/trunk/include/type_traits
    libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp

Modified: libcxx/trunk/include/bitset
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/bitset?rev=364842&r1=364841&r2=364842&view=diff
==============================================================================
--- libcxx/trunk/include/bitset (original)
+++ libcxx/trunk/include/bitset Mon Jul  1 12:59:34 2019
@@ -679,7 +679,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
         bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
-    template<class _CharT>
+    template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
         explicit bitset(const _CharT* __str,
                         typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
                         _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
@@ -760,7 +760,7 @@ private:
 };
 
 template <size_t _Size>
-template<class _CharT>
+template<class _CharT, class>
 bitset<_Size>::bitset(const _CharT* __str,
                       typename basic_string<_CharT>::size_type __n,
                       _CharT __zero, _CharT __one)

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=364842&r1=364841&r2=364842&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Jul  1 12:59:34 2019
@@ -4006,6 +4006,10 @@ inline constexpr bool is_constant_evalua
 }
 #endif
 
+
+template <class _CharT>
+using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
+
 _LIBCPP_END_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14

Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp?rev=364842&r1=364841&r2=364842&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp Mon Jul  1 12:59:34 2019
@@ -74,6 +74,18 @@ void test_string_ctor()
     }
 }
 
+struct Nonsense {
+    virtual ~Nonsense() {}
+};
+
+void test_for_non_eager_instantiation() {
+    // Ensure we don't accidentally instantiate `std::basic_string<Nonsense>`
+    // since it may not be well formed and can cause an error in the
+    // non-immediate context.
+    static_assert(!std::is_constructible<std::bitset<3>, Nonsense*>::value, "");
+    static_assert(!std::is_constructible<std::bitset<3>, Nonsense*, size_t, Nonsense&, Nonsense&>::value, "");
+}
+
 int main(int, char**)
 {
     test_string_ctor<0>();
@@ -85,6 +97,7 @@ int main(int, char**)
     test_string_ctor<64>();
     test_string_ctor<65>();
     test_string_ctor<1000>();
+    test_for_non_eager_instantiation();
 
   return 0;
 }




More information about the libcxx-commits mailing list