aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-04-05 16:22:51 -0400
committerJason Merrill <jason@redhat.com>2021-04-05 17:27:24 -0400
commitb07dd9b0d0e501a0083da79e2bca17041c007ec8 (patch)
tree7743419cf93ae59b0356f81b9cfc70f04b95896f /gcc
parent07f56824fd4da14a48030e698c8eb58de951c741 (diff)
downloadgcc-b07dd9b0d0e501a0083da79e2bca17041c007ec8.zip
gcc-b07dd9b0d0e501a0083da79e2bca17041c007ec8.tar.gz
gcc-b07dd9b0d0e501a0083da79e2bca17041c007ec8.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/typeck.c3
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C18
2 files changed, 21 insertions, 0 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 8535ecc..11dee7d 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -10215,6 +10215,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 0000000..b43cbe6
--- /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);
+}