Message ID | 875f093a-0b8f-7ddc-cd46-cece5a24cb2f@oracle.com |
---|---|
State | New |
Headers | show |
OK. On Wed, May 31, 2017 at 8:04 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote: > Hi, > > this one appears to be a rather simple case of missing diagnostic: in > convert_to_void we aren't calling maybe_warn_nodiscard when we strip an > INDIRECT_REF wrapping a CALL_EXPR thus we don't issue the diagnostic that we > normally provide for plain CALL_EXPRs (eg, for a func returning a plain > int). Tested x86_64-linux. > > Thanks, Paolo. > > ////////////////// >
Index: testsuite/g++.dg/cpp1z/nodiscard5.C =================================================================== --- testsuite/g++.dg/cpp1z/nodiscard5.C (revision 0) +++ testsuite/g++.dg/cpp1z/nodiscard5.C (working copy) @@ -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" } Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 248728) +++ cp/cvt.c (working copy) @@ -1296,6 +1296,8 @@ convert_to_void (tree expr, impl_conv_void implici && !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;