diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2018-07-04 11:44:35 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2018-07-04 11:44:35 +0000 |
commit | 1394444b2fc6a2fcc733bbe4487924e2478ed38e (patch) | |
tree | 20b37dfba3caf4f7603e1c4ac84d21cf4a6f01bd | |
parent | a6d13e084f73f7c65fd113febff71cb2ed260035 (diff) |
LWG 3076 basic_string CTAD ambiguity
When deduction guides are supported by the compiler (i.e. for C++17 and
later) replace two basic_string constructors by constrained function
templates as required by LWG 3075. In order to ensure that the pre-C++17
non-template constructors are still exported from the shared library
define a macro in src/c++11/string-inst.cc to force the non-template
declarations (this isn't strictly needed yet, because the string
instantiations are compiled with -std=gnu++11, but that is likely to
change).
Backport from mainline
2018-06-16 Jonathan Wakely <jwakely@redhat.com>
LWG 3076 basic_string CTAD ambiguity
* doc/xml/manual/intro.xml: Document LWG 3076 change.
* include/bits/basic_string.h
[__cpp_deduction_guides && !_GLIBCXX_DEFINING_STRING_INSTANTIATIONS]
(basic_string(const _CharT*, const _Alloc&)): Turn into a function
template constrained by _RequireAllocator.
(basic_string(size_type, _CharT, const _Alloc&)): Likewise.
* src/c++11/string-inst.cc (_GLIBCXX_DEFINING_STRING_INSTANTIATIONS):
Define.
* testsuite/21_strings/basic_string/cons/char/deduction.cc: Test
deduction
* testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc:
Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@262384 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog | 17 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/intro.xml | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 10 | ||||
-rw-r--r-- | libstdc++-v3/src/c++11/string-inst.cc | 6 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc | 17 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc | 17 |
6 files changed, 74 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b5815c6f53ff..c7ca508cc1e0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,6 +1,23 @@ 2018-07-04 Jonathan Wakely <jwakely@redhat.com> Backport from mainline + 2018-06-16 Jonathan Wakely <jwakely@redhat.com> + + LWG 3076 basic_string CTAD ambiguity + * doc/xml/manual/intro.xml: Document LWG 3076 change. + * include/bits/basic_string.h + [__cpp_deduction_guides && !_GLIBCXX_DEFINING_STRING_INSTANTIATIONS] + (basic_string(const _CharT*, const _Alloc&)): Turn into a function + template constrained by _RequireAllocator. + (basic_string(size_type, _CharT, const _Alloc&)): Likewise. + * src/c++11/string-inst.cc (_GLIBCXX_DEFINING_STRING_INSTANTIATIONS): + Define. + * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test + deduction + * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc: + Likewise. + + Backport from mainline 2018-06-14 Jonathan Wakely <jwakely@redhat.com> LWG 3075 basic_string needs deduction guides from basic_string_view diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 38b6eb36477b..5d20778c0c60 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1160,6 +1160,13 @@ requirements of the license of GCC. <listitem><para>Add noexcept. </para></listitem></varlistentry> + <varlistentry xml:id="manual.bugs.dr3076"><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&DR;#3076">3076</link>: + <emphasis><code>basic_string</code> CTAD ambiguity + </emphasis> + </term> + <listitem><para>Change constructors to constrained templates. + </para></listitem></varlistentry> + </variablelist> </section> diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 577ad5e2f712..2e6e1c6e5da3 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -506,6 +506,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __s Source C string. * @param __a Allocator to use (default is default allocator). */ +#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3076. basic_string CTAD ambiguity + template<typename = _RequireAllocator<_Alloc>> +#endif basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) : _M_dataplus(_M_local_data(), __a) { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); } @@ -516,6 +521,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @param __c Character to use. * @param __a Allocator to use (default is default allocator). */ +#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3076. basic_string CTAD ambiguity + template<typename = _RequireAllocator<_Alloc>> +#endif basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) : _M_dataplus(_M_local_data(), __a) { _M_construct(__n, __c); } diff --git a/libstdc++-v3/src/c++11/string-inst.cc b/libstdc++-v3/src/c++11/string-inst.cc index 567d817dd7b8..47a1c9af3ab1 100644 --- a/libstdc++-v3/src/c++11/string-inst.cc +++ b/libstdc++-v3/src/c++11/string-inst.cc @@ -35,6 +35,12 @@ # define _GLIBCXX_USE_CXX11_ABI 1 #endif +// Prevent the basic_string(const _CharT*, const _Alloc&) and +// basic_string(size_type, _CharT, const _Alloc&) constructors from being +// replaced by constrained function templates, so that we instantiate the +// pre-C++17 definitions. +#define _GLIBCXX_DEFINING_STRING_INSTANTIATIONS 1 + #include <string> // Instantiation configuration. diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc index cf6857c6678d..fc28467e29b2 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/deduction.cc @@ -138,3 +138,20 @@ test05() std::basic_string s4(sv, 2u, 6u, a); check_type<std::string>(s4); } + +void +test06() +{ + // LWG 3076 basic_string CTAD ambiguity + using namespace std; + string s0; + + basic_string s1(s0, 1, 1); + check_type<std::string>(s1); + + basic_string s2("cat"sv, 1, 1); + check_type<std::string>(s2); + + basic_string s3("cat", 1); + check_type<std::string>(s3); +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc index ea312ff653eb..c40651f13dbd 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc @@ -97,3 +97,20 @@ test05() std::basic_string s4(sv, 2u, 6u, a); check_type<std::wstring>(s4); } + +void +test06() +{ + // LWG 3076 basic_string CTAD ambiguity + using namespace std; + wstring s0; + + basic_string s1(s0, 1, 1); + check_type<std::wstring>(s1); + + basic_string s2(L"cat"sv, 1, 1); + check_type<std::wstring>(s2); + + basic_string s3(L"cat", 1); + check_type<std::wstring>(s3); +} |