From patchwork Fri Jun 15 14:19:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 929968 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-479803-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="Fuiowqvp"; 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 416jLb0mjwz9s2R for ; Sat, 16 Jun 2018 00:20: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=MAvZ9ItUSe0JnMEO2PxVHOMqQwaFvAHYqe3toHq2Fkc3XN+FlYpeU uIhoGn0EJnWzpLvsoL1ZSRUzOli8WcHzNcCxKaObKigTaND+Qcmq/upv8P8Ozt5O llBuCrAINcUEy0ieVBs1NIjrOPyE/ol0yR5eQdnM5RpDeO92Lq43m8= 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=IQvGKr6/k5FszoXv99+VboZ+d9E=; b=FuiowqvpJV/63rkmAVYE 0gDWk6G2qV2Ya+vRVbqgXnjdYEeY7DjkgmcYJfinajiNlGTW9YEb7qWM72CaggO7 4L1B9ArBzSzmlyATXRjQHvkeHURjaUZ2yQ9+KgGLWTxe6azgjPZM1ZmaSEBsEnSx xL2poGlXsrGSBcG2y3QAmes= Received: (qmail 70662 invoked by alias); 15 Jun 2018 14:19:48 -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 70585 invoked by uid 89); 15 Jun 2018 14:19:47 -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, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=decltype 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 14:19:46 +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 5D84D87A81; Fri, 15 Jun 2018 14:19:44 +0000 (UTC) Received: from localhost (unknown [10.33.36.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DCD92026990; Fri, 15 Jun 2018 14:19:43 +0000 (UTC) Date: Fri, 15 Jun 2018 15:19:43 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] LWG 2993 reference_wrapper conversion from T&& Message-ID: <20180615141943.GS6295@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) A DR approved at the Jacksonville meeting earlier this year. * doc/xml/manual/intro.xml: Document LWG 2993 change. * include/bits/refwrap.h (reference_wrapper(_Tp&)): Remove. (reference_wrapper(_Tp&&)): Remove. (reference_wrapper<_Up>(_Up&&)): Define new constructor as constrained template. (reference_wrapper): Add deduction guide. * testsuite/20_util/reference_wrapper/deduction.cc: New. * testsuite/20_util/reference_wrapper/lwg2993.cc: New. Tested powerpc64le-linux, committed to trunk. commit 626e3000f5751b5c9ac8ad8748583b4626229da3 Author: Jonathan Wakely Date: Fri Jun 15 01:40:42 2018 +0100 LWG 2993 reference_wrapper conversion from T&& * doc/xml/manual/intro.xml: Document LWG 2993 change. * include/bits/refwrap.h (reference_wrapper(_Tp&)): Remove. (reference_wrapper(_Tp&&)): Remove. (reference_wrapper<_Up>(_Up&&)): Define new constructor as constrained template. (reference_wrapper): Add deduction guide. * testsuite/20_util/reference_wrapper/deduction.cc: New. * testsuite/20_util/reference_wrapper/lwg2993.cc: New. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index b0fc131d1eb..90d43903def 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1160,6 +1160,14 @@ requirements of the license of GCC. Add noexcept. + 2993: + reference_wrapper<T> conversion from T&& + + + Replaced the constructors with a constrained template, + to prevent participation in overload resolution when not valid. + + 3074: Non-member functions for valarray should only deduce from the valarray diff --git a/libstdc++-v3/include/bits/refwrap.h b/libstdc++-v3/include/bits/refwrap.h index c1d46705b6b..2fdf231898f 100644 --- a/libstdc++-v3/include/bits/refwrap.h +++ b/libstdc++-v3/include/bits/refwrap.h @@ -291,14 +291,25 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type) { _Tp* _M_data; + static _Tp* _S_fun(_Tp& __r) noexcept { return std::__addressof(__r); } + static void _S_fun(_Tp&&) = delete; + + template> + using __not_same + = typename enable_if::value>::type; + public: typedef _Tp type; - reference_wrapper(_Tp& __indata) noexcept - : _M_data(std::__addressof(__indata)) - { } - - reference_wrapper(_Tp&&) = delete; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2993. reference_wrapper conversion from T&& + // 3041. Unnecessary decay in reference_wrapper + template, typename + = decltype(reference_wrapper::_S_fun(std::declval<_Up>()))> + reference_wrapper(_Up&& __uref) + noexcept(noexcept(reference_wrapper::_S_fun(std::declval<_Up>()))) + : _M_data(reference_wrapper::_S_fun(std::forward<_Up>(__uref))) + { } reference_wrapper(const reference_wrapper&) = default; @@ -320,6 +331,10 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type) } }; +#if __cpp_deduction_guides + template + reference_wrapper(_Tp&) -> reference_wrapper<_Tp>; +#endif /// Denotes a reference should be taken to a variable. template diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/deduction.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/deduction.cc new file mode 100644 index 00000000000..cc5b260cb16 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/deduction.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include + +void +test01() +{ + int i = 0; + std::reference_wrapper rw0(i); + [[maybe_unused]] std::reference_wrapper* p0 = &rw0; + [[maybe_unused]] int& r0 = rw0; + + std::reference_wrapper rw1(rw0); + [[maybe_unused]] std::reference_wrapper* p1 = &rw1; + [[maybe_unused]] int& r1 = rw1; +} + +void +test02() +{ + const int i = 0; + std::reference_wrapper rw0(i); + [[maybe_unused]] std::reference_wrapper* p0 = &rw0; + + std::reference_wrapper rw1(rw0); + [[maybe_unused]] std::reference_wrapper* p1 = &rw1; +} diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/lwg2993.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/lwg2993.cc new file mode 100644 index 00000000000..0a339486ef8 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/lwg2993.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include + +// LWG 2993. reference_wrapper conversion from T&& + +static_assert(std::is_convertible, + std::reference_wrapper>::value, + "LWG 2993 enables qualification conversions"); + +// The comments below are taken from the issue discussion and describe the +// behaviour before the resolution of LWG 2993. There should be no errors now. + +struct convertible_from_int { convertible_from_int(int) { } }; + +void +test01() +{ + + void meow(std::reference_wrapper); //#1 + void meow(convertible_from_int); //#2 + // error, ambiguous; would unambiguously call #2 if #1 instead took int& + meow(0); +} + +void +test02() +{ + std::reference_wrapper purr(); + + // error, ambiguous: ICS exists from int prvalue to + // reference_wrapper and from reference_wrapper to int + auto x = true ? purr() : 0; + + // error: no member 'type' because the conditional + // expression is ill-formed + using t = std::common_type_t, int>; +}