From c0cc62604f163289afaa37ba45f729ae31a45e71 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 2 Aug 2019 08:52:42 +0000 Subject: [PATCH] tree.c (handle_nodiscard_attribute): Do not warn about nodiscard applied to a constructor. /cp 2019-08-02 Paolo Carlini * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard applied to a constructor. /testsuite 2019-08-02 Paolo Carlini * g++.dg/cpp1z/nodiscard6.C: New. From-SVN: r274002 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/tree.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp1z/nodiscard6.C | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nodiscard6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b7183ac..4843537 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-08-02 Paolo Carlini + + * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard + applied to a constructor. + 2019-08-02 Martin Liska * decl.c (grok_op_properties): diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 37e24a1..27bc351 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8dc95b9..58a26d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-02 Paolo Carlini + + * g++.dg/cpp1z/nodiscard6.C: New. + 2019-08-02 Senthil Kumar Selvaraj * 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 index 0000000..d9813fc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nodiscard6.C @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } + +struct A +{ + [[nodiscard]] A(); +}; + +void foo() +{ + A(); // { dg-warning "ignoring return value" } +} -- 2.7.4