[libcxx] r292354 - Merge R292276: Fix std::string assignment ambiguity from braced initializer lists.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 18 00:43:25 PST 2017
Author: ericwf
Date: Wed Jan 18 02:43:24 2017
New Revision: 292354
URL: http://llvm.org/viewvc/llvm-project?rev=292354&view=rev
Log:
Merge R292276: Fix std::string assignment ambiguity from braced initializer lists.
When support for `basic_string_view` was added to string it also
added new assignment operators from `basic_string_view`. These caused
ambiguity when assigning from a braced initializer. This patch fixes
that regression by making the basic_string_view assignment operator
rank lower in overload resolution by making it a template.
Added:
libcxx/branches/release_40/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
Modified:
libcxx/branches/release_40/include/string
libcxx/branches/release_40/test/std/strings/basic.string/string.cons/string_view.pass.cpp
Modified: libcxx/branches/release_40/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/include/string?rev=292354&r1=292353&r2=292354&view=diff
==============================================================================
--- libcxx/branches/release_40/include/string (original)
+++ libcxx/branches/release_40/include/string Wed Jan 18 02:43:24 2017
@@ -818,6 +818,7 @@ public:
operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
basic_string& operator=(const basic_string& __str);
+ template <class = void>
_LIBCPP_INLINE_VISIBILITY
basic_string& operator=(__self_view __sv) {return assign(__sv);}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Added: libcxx/branches/release_40/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp?rev=292354&view=auto
==============================================================================
--- libcxx/branches/release_40/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp (added)
+++ libcxx/branches/release_40/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp Wed Jan 18 02:43:24 2017
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <string>
+
+// basic_string<charT,traits,Allocator>&
+// operator=(basic_string<charT,traits,Allocator>&& str);
+
+#include <string>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ // Test that assignment from {} and {ptr, len} are allowed and are not
+ // ambiguous.
+ {
+ std::string s = "hello world";
+ s = {};
+ assert(s.empty());
+ }
+ {
+ std::string s = "hello world";
+ s = {"abc", 2};
+ assert(s == "ab");
+ }
+}
Modified: libcxx/branches/release_40/test/std/strings/basic.string/string.cons/string_view.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/strings/basic.string/string.cons/string_view.pass.cpp?rev=292354&r1=292353&r2=292354&view=diff
==============================================================================
--- libcxx/branches/release_40/test/std/strings/basic.string/string.cons/string_view.pass.cpp (original)
+++ libcxx/branches/release_40/test/std/strings/basic.string/string.cons/string_view.pass.cpp Wed Jan 18 02:43:24 2017
@@ -28,12 +28,23 @@ test(std::basic_string_view<charT> sv)
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
+ {
S s2(sv);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
+ }
+ {
+ S s2;
+ s2 = sv;
+ LIBCPP_ASSERT(s2.__invariants());
+ assert(s2.size() == sv.size());
+ assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
+ assert(s2.get_allocator() == A());
+ assert(s2.capacity() >= s2.size());
+ }
}
template <class charT, class A>
@@ -42,12 +53,23 @@ test(std::basic_string_view<charT> sv, c
{
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
typedef typename S::traits_type T;
+ {
S s2(sv, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
+ }
+ {
+ S s2(a);
+ s2 = sv;
+ LIBCPP_ASSERT(s2.__invariants());
+ assert(s2.size() == sv.size());
+ assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
+ assert(s2.get_allocator() == a);
+ assert(s2.capacity() >= s2.size());
+ }
}
int main()
More information about the cfe-commits
mailing list