public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9846] c++: -Wunused, constant, and generic lambda [PR96311]
@ 2021-05-20 21:35 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-20 21:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8909ed58700694f5ba66499739edfea90a0fc813

commit r10-9846-g8909ed58700694f5ba66499739edfea90a0fc813
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 5 16:22:51 2021 -0400

    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.

Diff:
---
 gcc/cp/typeck.c                                     |  3 +++
 gcc/testsuite/g++.dg/cpp1y/lambda-generic-Wunused.C | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 6ebf6319efd..a85a75c81ae 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -10037,6 +10037,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);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-20 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 21:35 [gcc r10-9846] c++: -Wunused, constant, and generic lambda [PR96311] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).