https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118980

            Bug ID: 118980
           Summary: std::system_error should not be default constructible
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

We have a non-standard default argument on this constructor:

    system_error(error_code __ec = error_code())

The system_error(error_code) constructor was added to the C++0x WP by
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2422.htm#Issue24

That ctor was added to libstdc++ by r0-86777-g4514bed67d02fb but with a default
argument, but I don't know why. We don't have any tests that 

We should split the constructor into two, deprecate the default ctor for GCC
16, then remove it:

--- a/libstdc++-v3/include/std/system_error
+++ b/libstdc++-v3/include/std/system_error
@@ -561,7 +561,9 @@ namespace __adl_only
     error_code         _M_code;

   public:
-    system_error(error_code __ec = error_code())
+    [[__deprecated__]] system_error() : system_error(error_code{}) { }
+
+    system_error(error_code __ec)
     : runtime_error(__ec.message()), _M_code(__ec) { }

     system_error(error_code __ec, const string& __what)

We need to fix one test that currently uses the default constructor:

FAIL: 19_diagnostics/system_error/cons_virtual_derivation.cc  -std=gnu++17
(test for excess errors)

For now the fix will be to add a dg-warning for the -Wdeprecated-declaration
warning (or suppress it) but after we remove the default constructor we'll need
to find some way to construct a std::system_error in the
diamond_derivation_error class, which assumes that either it's default
constructible or can be constructed from a const char*.

N.B. https://cplusplus.github.io/LWG/issue3162 says the
system_error(error_code) ctor should be explicit, but it hasn't been approved.

Reply via email to