From: Paolo Carlini Date: Fri, 2 Aug 2019 08:52:42 +0000 (+0000) Subject: tree.c (handle_nodiscard_attribute): Do not warn about nodiscard applied to a constru... X-Git-Tag: upstream/12.2.0~22810 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0cc62604f163289afaa37ba45f729ae31a45e71;p=platform%2Fupstream%2Fgcc.git 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 --- 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" } +}