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 <ja...@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;
+}