]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: deleted after first declaration [PR101106]
authorJason Merrill <jason@redhat.com>
Thu, 17 Jun 2021 19:31:15 +0000 (15:31 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 21 Jun 2021 20:42:33 +0000 (16:42 -0400)
An explicitly deleted function must be deleted on its first declaration.  We
were diagnosing this error only with -Wpedantic, but always giving the
"previous declaration" note.  For GCC 11, keep the -Wpedantic dependency,
just make the note depend on the previous diagnostic.

PR c++/101106

gcc/cp/ChangeLog:

* decl.c (duplicate_decls): Condition note on return value of pedwarn.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/deleted15.C: New test.

gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/deleted15.C [new file with mode: 0644]

index d2fc1c1d4a30d565e3d61d84a906c385d6657c3f..0ed15f53596f521e1b7f6b7e4d724de060181ca3 100644 (file)
@@ -2160,11 +2160,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
          if (DECL_DELETED_FN (newdecl))
            {
              auto_diagnostic_group d;
-             pedwarn (newdecl_loc, OPT_Wpedantic,
-                      "deleted definition of %qD is not first declaration",
-                      newdecl);
-             inform (olddecl_loc,
-                     "previous declaration of %qD", olddecl);
+             if (pedwarn (newdecl_loc, OPT_Wpedantic, "deleted definition of "
+                          "%qD is not first declaration", newdecl))
+               inform (olddecl_loc,
+                       "previous declaration of %qD", olddecl);
            }
          DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
        }
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted15.C b/gcc/testsuite/g++.dg/cpp0x/deleted15.C
new file mode 100644 (file)
index 0000000..ab1893d
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/101106
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+int f();               // { dg-bogus "previous declaration" }
+int f() = delete;