From patchwork Thu Sep 8 18:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp382483wrt; Thu, 8 Sep 2022 11:31:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7O8SsaoPclImziOXLzniR3VFZTKoa4Kd5z1gQrUhk6RGLjy+VuAlfPA0SYzRbF931YmXWy X-Received: by 2002:a17:906:844d:b0:730:cd6a:a487 with SMTP id e13-20020a170906844d00b00730cd6aa487mr6792097ejy.50.1662661874426; Thu, 08 Sep 2022 11:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662661874; cv=none; d=google.com; s=arc-20160816; b=zUtoV/g7zFz7C5XFLIOAD7F7ZjYykuLAV7SoUhf23Cy3pxsYdmn5K9pd8uknTC+JD4 pckjdGTKqFXcBaFt8pniyiliY7VSOxTnkAIVjucqDl3N6xYRK75/w3xrqbRtpKPzi0pM uT5RoReIuiILJp6itnVTEl8LRRqlCNiTNVSpDXbg8Juugbiz+R9Xy3VYXrJpKjExtdba RKw/BfcZFAW17xfdyRwUURO8NZaP6rELfGXRKx5nSJ2EJsMU+DC6qUlS8i5hBM2Z5+Kn wY+A0K1Elgg9bJ6FKOO5od2lHWN064zgRYd9uAcrc7F5xldF+ptmGOqE5KJsUiZ/ebEU GFGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=M/VQfSSROv8HswFYwbxvAlm9NHrhnOUEIcldpwtwPVg=; b=Krfs9x3vc2KWtNq7SwgELIfnESbWZVY5F6ii7nvgdkSWctRZ+A5bVSbqDuExW1auct nfAKtXlAhBgsyO4n+Xmo8AcaFyNaYGZ8Dpr+kg+0vnI2IX8unRGafHr9VLK1p+/r1psG Xgp3RDUdKzY7t6pqrfUm/NrAj/dp2K+QgJBy82yXZ0XD1qRHb2LN2o+RU92IUetuRY53 2OByKXHmDCFjbB9aQvda6YPO2l91t6BnJOzj/+cf4lV1R4FQkLWLggYkqGO6bIJGsOaK +zk9YnHOk9Hw+LPVeB04K2dP0ckUd0m9I11sSdkEPzBgV/iNgU++n1QxE3GiKVdQY8u9 mHZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dBctEEyS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id sd14-20020a1709076e0e00b00731469b12d8si2710001ejc.963.2022.09.08.11.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 11:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dBctEEyS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E7B33858004 for ; Thu, 8 Sep 2022 18:30:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E7B33858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662661857; bh=M/VQfSSROv8HswFYwbxvAlm9NHrhnOUEIcldpwtwPVg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dBctEEySF49qeExxFoH9xeFPBGXRPbK/CWmOPJDL+UzDnD0FvXybB1goErh+0En1f 7m9nH4yUvrtgQdt9TImqmusv6pY2N3i3tyoJ/FHO/6VINHRldZ/wahubrP/Oxj8Onp l2H5HoXJIgm1Y374oJrrH6pzCCuSA5vk6wl8xyAA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0326A3858C74 for ; Thu, 8 Sep 2022 18:30:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0326A3858C74 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-101-GCWu_uM3PTGxtJn8B6MaDw-1; Thu, 08 Sep 2022 14:30:11 -0400 X-MC-Unique: GCWu_uM3PTGxtJn8B6MaDw-1 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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B382101A54E; Thu, 8 Sep 2022 18:30:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id E52E62026D4C; Thu, 8 Sep 2022 18:30:10 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Find make_error_code and make_error_condition via ADL only Date: Thu, 8 Sep 2022 19:30:10 +0100 Message-Id: <20220908183010.3290473-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743427337570536901?= X-GMAIL-MSGID: =?utf-8?q?1743427337570536901?= Tested powerpc64le-linux, pushed to trunk. -- >8 -- The new proposed resolution for LWG 3629 says that std::error_code and std::error_condition should only use ADL to find their customization points. This means we need to use a poison pill to prevent lookup from finding overloads in the enclosing namespaces. We can also remove the forward declarations of std::make_error_code and std::make_error_condition, because they aren't needed now. ADL can find them anyway (when std is an associated namespace), and unqualified name lookup will not (and should not) find them. libstdc++-v3/ChangeLog: * include/std/system_error (__adl_only::make_error_code): Add deleted function. (__adl_only::make_error_condition): Likewise. (error_code::error_code(ErrorCodeEnum)): Add using-declaration for deleted function. (error_condition::error_condition(ErrorConditionEnum)): Likewise. * testsuite/19_diagnostics/error_code/cons/lwg3629.cc: New test. * testsuite/19_diagnostics/error_condition/cons/lwg3629.cc: New test. --- libstdc++-v3/include/std/system_error | 18 +++++-- .../19_diagnostics/error_code/cons/lwg3629.cc | 48 +++++++++++++++++++ .../error_condition/cons/lwg3629.cc | 48 +++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/19_diagnostics/error_code/cons/lwg3629.cc create mode 100644 libstdc++-v3/testsuite/19_diagnostics/error_condition/cons/lwg3629.cc diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 050439427cc..e12bb2f0e1e 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -195,7 +195,11 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @{ */ - error_code make_error_code(errc) noexcept; +namespace __adl_only +{ + void make_error_code() = delete; + void make_error_condition() = delete; +} /** Class error_code * @@ -231,7 +235,10 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) template> error_code(_ErrorCodeEnum __e) noexcept - { *this = make_error_code(__e); } + { + using __adl_only::make_error_code; + *this = make_error_code(__e); + } error_code(const error_code&) = default; error_code& operator=(const error_code&) = default; @@ -330,8 +337,6 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e) { return (__os << __e.category().name() << ':' << __e.value()); } - error_condition make_error_condition(errc) noexcept; - /** Class error_condition * * This class represents error conditions that may be visible at an API @@ -363,7 +368,10 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) template> error_condition(_ErrorConditionEnum __e) noexcept - { *this = make_error_condition(__e); } + { + using __adl_only::make_error_condition; + *this = make_error_condition(__e); + } error_condition(const error_condition&) = default; error_condition& operator=(const error_condition&) = default; diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/lwg3629.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/lwg3629.cc new file mode 100644 index 00000000000..b1e0b7f0c81 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/cons/lwg3629.cc @@ -0,0 +1,48 @@ +// { dg-do compile { target c++11 } } + +// 3629. make_error_code and make_error_condition are customization points +// Verify that make_error_code is looked up using ADL only. + +namespace user +{ + struct E1; +} + +// N.B. not in associated namespace of E1, and declared before . +user::E1 make_error_code(user::E1); + +#include // declares std::make_error_code(future_errc) +#include + +namespace user +{ + struct E1 + { + operator std::error_code() const; + }; + + struct E2 + { + operator std::future_errc() const; + }; + + struct E3 + { + operator std::errc() const; + }; +} + +template<> struct std::is_error_code_enum : std::true_type { }; +template<> struct std::is_error_code_enum : std::true_type { }; +template<> struct std::is_error_code_enum : std::true_type { }; + +// ::make_error_code(E1) should not be found by name lookup. +std::error_code e1( user::E1{} ); // { dg-error "here" } + +// std::make_error_code(errc) should not be found by name lookup. +std::error_code e2( user::E2{} ); // { dg-error "here" } + +// std::make_error_code(future_errc) should not be found by name lookup. +std::error_code e3( user::E3{} ); // { dg-error "here" } + +// { dg-error "use of deleted function" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/cons/lwg3629.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/cons/lwg3629.cc new file mode 100644 index 00000000000..e34b53de8a1 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/cons/lwg3629.cc @@ -0,0 +1,48 @@ +// { dg-do compile { target c++11 } } + +// 3629. make_error_code and make_error_condition are customization points +// Verify that make_error_condition is looked up using ADL only. + +namespace user +{ + struct E1; +} + +// N.B. not in associated namespace of E1, and declared before . +user::E1 make_error_condition(user::E1); + +#include // declares std::make_error_condition(future_errc) +#include + +namespace user +{ + struct E1 + { + operator std::error_code() const; + }; + + struct E2 + { + operator std::future_errc() const; + }; + + struct E3 + { + operator std::errc() const; + }; +} + +template<> struct std::is_error_condition_enum : std::true_type { }; +template<> struct std::is_error_condition_enum : std::true_type { }; +template<> struct std::is_error_condition_enum : std::true_type { }; + +// ::make_error_condition(E1) should not be found by name lookup. +std::error_condition e1( user::E1{} ); // { dg-error "here" } + +// std::make_error_condition(errc) should not be found by name lookup. +std::error_condition e2( user::E2{} ); // { dg-error "here" } + +// std::make_error_condition(future_errc) should not be found by name lookup. +std::error_condition e3( user::E3{} ); // { dg-error "here" } + +// { dg-error "use of deleted function" "" { target *-*-* } 0 }