From ac853c9071ab9a8df483c26fe8672732546c51ab Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 1 Jun 2017 10:20:27 +0000 Subject: [PATCH] re PR c++/80896 ([[nodiscard]] is ignored for functions returning references) /cp 2017-06-01 Paolo Carlini PR c++/80896 * cvt.c (convert_to_void): Possibly call maybe_warn_nodiscard for case INDIRECT_REF too in the main switch. /testsuite 2017-06-01 Paolo Carlini PR c++/80896 * g++.dg/cpp1z/nodiscard5.C: New. From-SVN: r248784 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cvt.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1z/nodiscard5.C | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nodiscard5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bbb6a533d85..60fe1a5436a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-06-01 Paolo Carlini + + PR c++/80896 + * cvt.c (convert_to_void): Possibly call maybe_warn_nodiscard + for case INDIRECT_REF too in the main switch. + 2017-05-31 Jason Merrill PR c++/80840 - ICE with constexpr and reference diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index e8a7ee29465..6b28ef65074 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1296,6 +1296,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) && !is_reference) warning_at (loc, OPT_Wunused_value, "value computed is not used"); expr = TREE_OPERAND (expr, 0); + if (TREE_CODE (expr) == CALL_EXPR) + maybe_warn_nodiscard (expr, implicit); } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 952bc9328ca..a1212f24b6b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-01 Paolo Carlini + + PR c++/80896 + * g++.dg/cpp1z/nodiscard5.C: New. + 2017-06-01 Claudiu Zissulescu * gcc.target/arc/pr9001195952.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/nodiscard5.C b/gcc/testsuite/g++.dg/cpp1z/nodiscard5.C new file mode 100644 index 00000000000..fa9a974355b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nodiscard5.C @@ -0,0 +1,7 @@ +// PR c++/80896 +// { dg-do compile { target c++11 } } + +int x = 42; +[[nodiscard]] int& func() { return x; } + +int main() { func(); } // { dg-warning "ignoring return value" } -- 2.30.2