[libcxx] r292276 - Fix std::string assignment ambiguity from braced initializer lists.

Dimitry Andric via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 23 06:45:01 PST 2017


> On 17 Jan 2017, at 23:10, Eric Fiselier via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Author: ericwf
> Date: Tue Jan 17 16:10:32 2017
> New Revision: 292276
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=292276&view=rev
> Log:
> 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/trunk/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp
> Modified:
>    libcxx/trunk/include/string
>    libcxx/trunk/test/std/strings/basic.string/string.cons/string_view.pass.cpp
> 
> Modified: libcxx/trunk/include/string
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=292276&r1=292275&r2=292276&view=diff
> ==============================================================================
> --- libcxx/trunk/include/string (original)
> +++ libcxx/trunk/include/string Tue Jan 17 16:10:32 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

Hi Eric,

This fix has one side effect that shows up in https://bugs.freebsd.org/216404 now: gcc has until recently defaulted to -std=gnu++98, and this makes it complain about the default template argument:

In file included from /usr/include/c++/v1/__locale:15:0,
                 from /usr/include/c++/v1/ios:216,
                 from /usr/include/c++/v1/iostream:38,
                 from a.cc:1:
/usr/include/c++/v1/string:823:45: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
     basic_string& operator=(__self_view __sv)  {return assign(__sv);}
                                             ^

Maybe the defaulted template argument can be surrounded with _LIBCPP_CXX03_LANG?

-Dimitry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170123/769544e9/attachment.sig>


More information about the cfe-commits mailing list