re PR c++/80896 ([[nodiscard]] is ignored for functions returning references)
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 1 Jun 2017 10:20:27 +0000 (10:20 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 1 Jun 2017 10:20:27 +0000 (10:20 +0000)
/cp
2017-06-01  Paolo Carlini  <paolo.carlini@oracle.com>

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  <paolo.carlini@oracle.com>

PR c++/80896
* g++.dg/cpp1z/nodiscard5.C: New.

From-SVN: r248784

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

index bbb6a533d8539d2b343bd8eeeca7d9e7900968de..60fe1a5436a2e76a68a47f33dfd2992644208d09 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       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  <jason@redhat.com>
 
        PR c++/80840 - ICE with constexpr and reference
index e8a7ee29465d089dbd0dc979259c37e1a8691ba2..6b28ef65074bfc5b30fbdf4c9562ddbae4825250 100644 (file)
@@ -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;
index 952bc9328ca7ec9c7884e0c75bb7ef1d5306d0e5..a1212f24b6b5b9ca05e637c9e60472dd8ed8a799 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/80896
+       * g++.dg/cpp1z/nodiscard5.C: New.
+
 2017-06-01  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * 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 (file)
index 0000000..fa9a974
--- /dev/null
@@ -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" }