This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/39164 (redefinition of =default)


Just needed to adjust the existing check for redefinition of an implicitly declared function to cover =default as well.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 4b566a62381c2701abe930c49fd2d41e5f7ce3d1
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 3 11:33:24 2011 -0400

    	PR c++/39164
    	* decl.c (grokfndecl): Diagnose redefinition of defaulted fn.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 30f92da..984d1f2 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7418,6 +7418,12 @@ grokfndecl (tree ctype,
 	      error ("definition of implicitly-declared %qD", old_decl);
 	      return NULL_TREE;
 	    }
+	  else if (DECL_DEFAULTED_FN (old_decl))
+	    {
+	      error ("definition of explicitly-defaulted %q+D", decl);
+	      error ("%q+#D explicitly defaulted here", old_decl);
+	      return NULL_TREE;
+	    }
 
 	  /* Since we've smashed OLD_DECL to its
 	     DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted31.C b/gcc/testsuite/g++.dg/cpp0x/defaulted31.C
new file mode 100644
index 0000000..de6a298
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted31.C
@@ -0,0 +1,16 @@
+// PR c++/39164
+// { dg-options -std=c++0x }
+
+struct A
+{
+  A() { }			// { dg-error "defined" }
+  ~A() = default;		// { dg-error "defaulted" }
+};
+
+A::A() = default;		// { dg-error "redefinition" }
+A::~A() noexcept (true) { }	// { dg-error "defaulted" }
+
+int main()
+{
+  A a;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]