From patchwork Fri Jun 15 23:46:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 930284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-479863-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ojQ/K3RZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 416xws1qBSz9s3R for ; Sat, 16 Jun 2018 09:47:06 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=QpUDJFzratgJE2sDptYe/o1VxR7ixhu0e3x9R/Nt1aqZykM+SoNb9 RqbG7gOtSvY/cq9192yJVKUJXYrlJ7qMhukszf/shc1oHPH5UDV6CVA6kRLf4pO3 iXX3VVRcAzydVgg7XcT8IkEx4ebiSIsJat4G+H9dsNLFNCyf+1Nbpk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=zNzNh8BNmt+dGEfJlaW/ktdn29k=; b=ojQ/K3RZB7FAzRiV/S5M IV1HFlWgnj/M0V0qS3uSxy4PhQB9AEkoZoIbcAb2VEg9kDLxryzanAPFcrlTH0yR vcWjXnG9SxAkxuSLSuULcHYr/5t+qrOm2+frvhhxjDUrBXS6+4cKWAotxGHDGlS1 xhg4k9ZVD/Jix7I9epxwExw= Received: (qmail 58262 invoked by alias); 15 Jun 2018 23:46:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 58241 invoked by uid 89); 15 Jun 2018 23:46:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ambiguity, prec, instantiate, 973 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Jun 2018 23:46:55 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8BF34070481; Fri, 15 Jun 2018 23:46:53 +0000 (UTC) Received: from localhost (unknown [10.33.36.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id A77E22026DEF; Fri, 15 Jun 2018 23:46:53 +0000 (UTC) Date: Sat, 16 Jun 2018 00:46:52 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] LWG 3076 basic_string CTAD ambiguity Message-ID: <20180615234652.GA19537@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) 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 3076. 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). 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. Tested powerpc64le-linux, committed to trunk. commit d4fe0dd3286562ffa26b993c9ee8e80c62762dc6 Author: redi Date: Thu Jun 14 20:27:04 2018 +0000 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). 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. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 90d43903def..fea07e2bb5f 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1176,6 +1176,13 @@ requirements of the license of GCC. they will allow conversions from other types to the value_type. + 3076: + basic_string CTAD ambiguity + + + Change constructors to constrained templates. + + diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 577ad5e2f71..2e6e1c6e5da 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> +#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> +#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 567d817dd7b..47a1c9af3ab 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 // 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 cf6857c6678..fc28467e29b 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(s4); } + +void +test06() +{ + // LWG 3076 basic_string CTAD ambiguity + using namespace std; + string s0; + + basic_string s1(s0, 1, 1); + check_type(s1); + + basic_string s2("cat"sv, 1, 1); + check_type(s2); + + basic_string s3("cat", 1); + check_type(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 ea312ff653e..c40651f13db 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(s4); } + +void +test06() +{ + // LWG 3076 basic_string CTAD ambiguity + using namespace std; + wstring s0; + + basic_string s1(s0, 1, 1); + check_type(s1); + + basic_string s2(L"cat"sv, 1, 1); + check_type(s2); + + basic_string s3(L"cat", 1); + check_type(s3); +}