diff mbox series

PR libstdc++/85843 fix "should be explicitly initialized" warnings

Message ID 20180520235002.GA30361@redhat.com
State New
Headers show
Series PR libstdc++/85843 fix "should be explicitly initialized" warnings | expand

Commit Message

Jonathan Wakely May 20, 2018, 11:50 p.m. UTC
PR libstdc++/85843
	* src/c++11/cow-stdexcept.cc (logic_error, runtime_error): Explicitly
	initialize base class to avoid warnings.

Tested powerpc64le-linux, committed to trunk.
commit e64c045676caee3153d62bdaaf207bb331f10d3d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon May 21 00:24:05 2018 +0100

    PR libstdc++/85843 fix "should be explicitly initialized" warnings
    
            PR libstdc++/85843
            * src/c++11/cow-stdexcept.cc (logic_error, runtime_error): Explicitly
            initialize base class to avoid warnings.

Comments

Jason Merrill May 21, 2018, 3:52 a.m. UTC | #1
On Sun, May 20, 2018 at 7:50 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
>         PR libstdc++/85843
>         * src/c++11/cow-stdexcept.cc (logic_error, runtime_error): Explicitly
>         initialize base class to avoid warnings.

And this patch fixes the warning to treat defaulted constructors the
same as implicitly-declared constructors.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit b4bb335521d3993cc3fac3295d0461c376d52907
Author: Jason Merrill <jason@redhat.com>
Date:   Sun May 20 22:26:04 2018 -0400

            PR libstdc++/85843 - warning in logic_error copy constructor.
    
            * class.c (type_has_user_nondefault_constructor): Check for a
            user-provided ctor, not user-declared.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 4960b4b5593..a9a0fa92727 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4884,7 +4884,7 @@ default_ctor_p (tree fn)
 	  && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
 }
 
-/* Returns true iff class T has a user-defined constructor that can be called
+/* Returns true iff class T has a user-provided constructor that can be called
    with more than zero arguments.  */
 
 bool
@@ -4896,7 +4896,7 @@ type_has_user_nondefault_constructor (tree t)
   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
     {
       tree fn = *iter;
-      if (!DECL_ARTIFICIAL (fn)
+      if (user_provided_p (fn)
 	  && (TREE_CODE (fn) == TEMPLATE_DECL
 	      || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
 		  != NULL_TREE)))
diff --git a/gcc/testsuite/g++.dg/warn/Wextra-4.C b/gcc/testsuite/g++.dg/warn/Wextra-4.C
new file mode 100644
index 00000000000..5c33c271154
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wextra-4.C
@@ -0,0 +1,15 @@
+// PR libstdc++/85843
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wextra }
+
+struct A
+{
+  A();
+  A(const A&) = default;
+};
+
+struct B : A
+{
+  B(): A() { }
+  B(const B&) { }
+};
diff mbox series

Patch

diff --git a/libstdc++-v3/src/c++11/cow-stdexcept.cc b/libstdc++-v3/src/c++11/cow-stdexcept.cc
index 7b42da1e133..5ad3d94ae31 100644
--- a/libstdc++-v3/src/c++11/cow-stdexcept.cc
+++ b/libstdc++-v3/src/c++11/cow-stdexcept.cc
@@ -56,13 +56,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Copy constructors and assignment operators defined using COW std::string
 
   logic_error::logic_error(const logic_error& e) noexcept
-  : _M_msg(e._M_msg) { }
+  : exception(e), _M_msg(e._M_msg) { }
 
   logic_error& logic_error::operator=(const logic_error& e) noexcept
   { _M_msg = e._M_msg; return *this; }
 
   runtime_error::runtime_error(const runtime_error& e) noexcept
-  : _M_msg(e._M_msg) { }
+  : exception(e), _M_msg(e._M_msg) { }
 
   runtime_error&
   runtime_error::operator=(const runtime_error& e) noexcept