From patchwork Thu Jun 14 20:26: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: 929702 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-479766-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="dxUttgUY"; 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 416FXg2cqkz9s3C for ; Fri, 15 Jun 2018 06:27:14 +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=sDCPkijfSxU/tIqxUdiZb3Yby2y0JmRn8SC5yXeoH79Hi1CNEMKBb d27NRhGHy5wqMx3s2fPvlCNmRtDhLFU6/5TaUGl2938V82cg1ESFPQhx+lbiguDR YKxzylEa9WtAiCaSJCPGSYLNMVyAE21fWNshYGuXWB8iIHk5sOqtYs= 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=RI8eTtTe2H+AcSgZGEmJP/GYxYg=; b=dxUttgUYSDG0B0ofOy7F LVop8Kijk3SeO/XvVajfnfv/P3bfjBT79cKW8maUT1u8XMdgEzRf9DAGLZU2+y70 G3P7wY8RRoIXVCFpI14ek6twtUBjOIfcNzstTTlbmP+ruTSwMKlWxpR5JOR8GNf7 E0ry0rbQwlv218uq/fM18kU= Received: (qmail 63264 invoked by alias); 14 Jun 2018 20:26:57 -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 63238 invoked by uid 89); 14 Jun 2018 20:26:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1183, ua, LA, la 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; Thu, 14 Jun 2018 20:26: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 E91AF406DE3D; Thu, 14 Jun 2018 20:26:53 +0000 (UTC) Received: from localhost (unknown [10.33.36.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 902E12022DF5; Thu, 14 Jun 2018 20:26:53 +0000 (UTC) Date: Thu, 14 Jun 2018 21:26:52 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] LWG 3075 basic_string needs deduction guides from basic_string_view Message-ID: <20180614202652.GA9787@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test deduction from string views. * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc: Likewise. Tested powerpc64le-linux, committed to trunk. This is probably worth backporting to gcc-8-branch too. commit 5246fd69a47d96b48e1dcdd33c18246c2336af8e Author: Jonathan Wakely Date: Thu Jun 14 20:51:00 2018 +0100 LWG 3075 basic_string needs deduction guides from basic_string_view * testsuite/21_strings/basic_string/cons/char/deduction.cc: Test deduction from string views. * testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc: Likewise. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 5bffa1c72a1..fbac38ae973 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -5873,6 +5873,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 typename = _RequireAllocator<_Allocator>> basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3075. basic_string needs deduction guides from basic_string_view + template, + typename = _RequireAllocator<_Allocator>> + basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; + + template, + typename = _RequireAllocator<_Allocator>> + basic_string(basic_string_view<_CharT, _Traits>, + typename basic_string<_CharT, _Traits, _Allocator>::size_type, + typename basic_string<_CharT, _Traits, _Allocator>::size_type, + const _Allocator& = _Allocator()) + -> basic_string<_CharT, _Traits, _Allocator>; _GLIBCXX_END_NAMESPACE_CXX11 #endif 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 f7dee1e6141..cf6857c6678 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 @@ -118,3 +118,23 @@ test04() std::basic_string s4((char32_t)1, U'a', std::allocator()); check_type(s4); } + +void +test05() +{ + // LWG 3075 basic_string needs deduction guides from basic_string_view + std::string_view sv{"A View to a Kill"}; + const std::allocator a; + + std::basic_string s1(sv); + check_type(s1); + + std::basic_string s2(sv, a); + check_type(s2); + + std::basic_string s3(sv, 2u, 6u); + check_type(s3); + + std::basic_string s4(sv, 2u, 6u, a); + check_type(s4); +} 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 7fe367b56dd..ea312ff653e 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 @@ -77,3 +77,23 @@ test02() std::basic_string s4((wchar_t)1, L'a', std::allocator()); check_type(s4); } + +void +test05() +{ + // LWG 3075 basic_string needs deduction guides from basic_string_view + std::wstring_view sv{L"A View to a Kill"}; + const std::allocator a; + + std::basic_string s1(sv); + check_type(s1); + + std::basic_string s2(sv, a); + check_type(s2); + + std::basic_string s3(sv, 2u, 6u); + check_type(s3); + + std::basic_string s4(sv, 2u, 6u, a); + check_type(s4); +}