tree.c (handle_nodiscard_attribute): Do not warn about nodiscard applied to a constru...
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 2 Aug 2019 08:52:42 +0000 (08:52 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 2 Aug 2019 08:52:42 +0000 (08:52 +0000)
/cp
2019-08-02  Paolo Carlini  <paolo.carlini@oracle.com>

* tree.c (handle_nodiscard_attribute): Do not warn about nodiscard
applied to a constructor.

/testsuite
2019-08-02  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/cpp1z/nodiscard6.C: New.

From-SVN: r274002

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/nodiscard6.C [new file with mode: 0644]

index b7183ac4c05cca2f972decf23f45983d3e60eceb..48435375aa0445815d334585682e04e593a31cbb 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard
+       applied to a constructor.
+
 2019-08-02  Martin Liska  <mliska@suse.cz>
 
        * decl.c (grok_op_properties):
index 37e24a1669cc5a50b0413a678f9bae6b6271b147..27bc35198bba272e2f11e7fa574abc9470131108 100644 (file)
@@ -4361,7 +4361,8 @@ handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
 {
   if (TREE_CODE (*node) == FUNCTION_DECL)
     {
-      if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
+      if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
+         && !DECL_CONSTRUCTOR_P (*node))
        warning_at (DECL_SOURCE_LOCATION (*node),
                    OPT_Wattributes, "%qE attribute applied to %qD with void "
                    "return type", name, *node);
index 8dc95b986f693f8ed44ae42b31909d6e8282c890..58a26d11f0f8a3451eedbb71a8ffce91bf89b3b2 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/cpp1z/nodiscard6.C: New.
+
 2019-08-02  Senthil Kumar Selvaraj  <senthilkumar.selvaraj@microchip.com>
 
        * gcc.dg/torture/ssa-fre-5.c: Add dg-require-effective-target int32.
diff --git a/gcc/testsuite/g++.dg/cpp1z/nodiscard6.C b/gcc/testsuite/g++.dg/cpp1z/nodiscard6.C
new file mode 100644 (file)
index 0000000..d9813fc
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  [[nodiscard]] A();
+};
+
+void foo()
+{
+  A();  // { dg-warning "ignoring return value" }
+}