From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 2B7973858C74; Thu, 8 Sep 2022 18:29:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B7973858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662661787; bh=ToEgHROcqrMlUijh1QEo7TwGjumWJdY45M8cb2EuTMI=; h=From:To:Subject:Date:From; b=ZFKWsWVPbUEk9Nre+r0VFp3jAJZ+s609mAqZ1VAEOUVSWKbRXfseKlZkquIV/0Zeq ehe0G5f8tg1/MjQqqqL2Z0F23qomwX4Npt/UlmU7uKRRZfkx4kiIoUNpFNKgFcu4tj fwwMLj9pK66GExQ1xRh1MrPZhSIPVhzrBAu1LfKg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2547] libstdc++: Find make_error_code and make_error_condition via ADL only X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 7a6564c9b277d9f93582605758d57457de696deb X-Git-Newrev: d3883dc77b1426984c0edea6081f57ed2305c9f2 Message-Id: <20220908182947.2B7973858C74@sourceware.org> Date: Thu, 8 Sep 2022 18:29:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d3883dc77b1426984c0edea6081f57ed2305c9f2 commit r13-2547-gd3883dc77b1426984c0edea6081f57ed2305c9f2 Author: Jonathan Wakely Date: Wed Sep 7 20:17:04 2022 +0100 libstdc++: Find make_error_code and make_error_condition via ADL only 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. Diff: --- libstdc++-v3/include/std/system_error | 18 +++++--- .../19_diagnostics/error_code/cons/lwg3629.cc | 48 ++++++++++++++++++++++ .../19_diagnostics/error_condition/cons/lwg3629.cc | 48 ++++++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) 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 }