From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 57318385842B for ; Thu, 23 Sep 2021 15:09:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 57318385842B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-217-jTw0ggDvOlSXFZVEQ1PWOg-1; Thu, 23 Sep 2021 11:09:17 -0400 X-MC-Unique: jTw0ggDvOlSXFZVEQ1PWOg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FE1E1084686; Thu, 23 Sep 2021 15:09:16 +0000 (UTC) Received: from localhost (unknown [10.33.36.241]) by smtp.corp.redhat.com (Postfix) with ESMTP id B484C5D9CA; Thu, 23 Sep 2021 15:09:15 +0000 (UTC) Date: Thu, 23 Sep 2021 16:09:14 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: std::system_category should know meaning of zero [PR102425] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="phh38h/TA7VZOPlQ" Content-Disposition: inline X-Spam-Status: No, score=-14.5 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2021 15:09:21 -0000 --phh38h/TA7VZOPlQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. Tested x86_64-linux. Committed to trunk. --phh38h/TA7VZOPlQ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit ce01e2e64c340dadb55a8a24c545a13e654804d4 Author: Jonathan Wakely Date: Wed Sep 22 11:58:20 2021 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. diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index f12290adaee..6c79202eb0e 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(); +} --phh38h/TA7VZOPlQ--