diff options
author | Jason Merrill <jason@redhat.com> | 2021-04-05 16:22:51 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-05-13 13:39:30 -0400 |
commit | aa3e2a211933efaeb6ecd0a69f196606b8a40b43 (patch) | |
tree | 54b80fccc2b1af2a6cf6b8a1542ad3e2d0724ee7 | |
parent | e0cc2713a4076edd4f20b80b0fe217c9ab1676b2 (diff) |
c++: -Wunused, constant, and generic lambda [PR96311]
We never called mark_use for a return value in a function with dependent
return type. In that situation we don't know if the use is as an rvalue or
lvalue, but we can use mark_exp_read instead.
gcc/cp/ChangeLog:
PR c++/96311
* typeck.c (check_return_expr): Call mark_exp_read in dependent
case.
gcc/testsuite/ChangeLog:
PR c++/96311
* g++.dg/cpp1y/lambda-generic-Wunused.C: New test.
-rw-r--r-- | gcc/cp/typeck.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 29e60436afd..39f354a373f 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9720,6 +9720,9 @@ check_return_expr (tree retval, bool *no_warning) dependent: /* We should not have changed the return value. */ gcc_assert (retval == saved_retval); + /* We don't know if this is an lvalue or rvalue use, but + either way we can mark it as read. */ + mark_exp_read (retval); return retval; } diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C new file mode 100644 index 00000000000..b43cbe6b675 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C @@ -0,0 +1,18 @@ +// PR c++/96311 +// { dg-do compile { target c++14 } } +// { dg-additional-options -Wunused } + +auto foo() +{ + constexpr int used = 0; + return + [](auto unused) + { + return used; + }; +} + +int main() +{ + foo()(42); +} |