From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id F2425385781F; Tue, 12 Oct 2021 10:59:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2425385781F 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 r11-9110] libstdc++: std::system_category should know meaning of zero [PR102425] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 90a4981e0951687056ec4735cfd3043b35a23502 X-Git-Newrev: da206878f64ef66b1f7527c4d87e8baf9a5c5bfd Message-Id: <20211012105917.F2425385781F@sourceware.org> Date: Tue, 12 Oct 2021 10:59:17 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 10:59:18 -0000 https://gcc.gnu.org/g:da206878f64ef66b1f7527c4d87e8baf9a5c5bfd commit r11-9110-gda206878f64ef66b1f7527c4d87e8baf9a5c5bfd Author: Jonathan Wakely Date: Wed Sep 22 11:58:20 2021 +0100 libstdc++: std::system_category should know meaning of zero [PR102425] Although 0 is not an errno value, it should still be recognized as corresponding to a value belonging to the generic_category(). Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/102425 * src/c++11/system_error.cc (system_error_category::default_error_condition): Add 0 to switch. * testsuite/19_diagnostics/error_category/102425.cc: New test. (cherry picked from commit ce01e2e64c340dadb55a8a24c545a13e654804d4) Diff: --- libstdc++-v3/src/c++11/system_error.cc | 3 +++ .../testsuite/19_diagnostics/error_category/102425.cc | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index 23fb6182825..0ee3ed81961 100644 --- a/libstdc++-v3/src/c++11/system_error.cc +++ b/libstdc++-v3/src/c++11/system_error.cc @@ -70,6 +70,8 @@ namespace virtual std::error_condition default_error_condition(int ev) const noexcept { + // Use generic category for all known POSIX errno values (including zero) + // and system category otherwise. switch (ev) { // List of errno macros from [cerrno.syn]. @@ -310,6 +312,7 @@ namespace #ifdef EXDEV case EXDEV: #endif + case 0: return std::error_condition(ev, std::generic_category()); /* Additional system-dependent mappings from non-standard error codes diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc new file mode 100644 index 00000000000..069b5e284e1 --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc @@ -0,0 +1,18 @@ +// { dg-do run { target c++11 } } +#include +#include + +void test01() +{ + // PR libstdc++/102425 + VERIFY( std::error_code() == std::error_condition() ); + + auto zero = std::system_category().default_error_condition(0); + // This is the condition that the equality above relies on: + VERIFY( zero.category() == std::generic_category() ); +} + +int main() +{ + test01(); +}