https://gcc.gnu.org/g:e6b115be1c392de415925282a38f28cd78cb6c35

commit r14-10359-ge6b115be1c392de415925282a38f28cd78cb6c35
Author: Patrick Palka <ppa...@redhat.com>
Date:   Tue Jun 25 20:07:15 2024 -0400

    c++: decltype of capture proxy of ref [PR115504]
    
    The finish_decltype_type capture proxy handling added in r14-5330 was
    incorrectly stripping references in the type of the captured variable.
    
            PR c++/115504
    
    gcc/cp/ChangeLog:
    
            * semantics.cc (finish_decltype_type): Don't strip the reference
            type (if any) of a capture proxy's captured variable.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1y/decltype-auto8.C: New test.
    
    Reviewed-by: Jason Merrill <ja...@redhat.com>
    (cherry picked from commit 737449e5f233feb682b5dd2cc153892ad90a79bd)

Diff:
---
 gcc/cp/semantics.cc                         |  1 -
 gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d944decd329..b18fc7c61be 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11904,7 +11904,6 @@ finish_decltype_type (tree expr, bool 
id_expression_or_member_access_p,
                {
                  expr = DECL_CAPTURED_VARIABLE (expr);
                  type = TREE_TYPE (expr);
-                 type = non_reference (type);
                }
              else
                {
diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C 
b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C
new file mode 100644
index 00000000000..55135cecf72
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C
@@ -0,0 +1,22 @@
+// PR c++/115504
+// { dg-do compile { target c++14 } }
+
+void f(int& x, const int& y) {
+  [&x]() {
+    decltype(auto) a = x;
+    using type = decltype(x);
+    using type = decltype(a);
+    using type = int&; // not 'int'
+  };
+
+  [x]() {
+    decltype(auto) a = x; // { dg-error "discards qualifiers" }
+  };
+
+  [x]() mutable {
+    decltype(auto) a = x;
+    using type = decltype(x);
+    using type = decltype(a);
+    using type = int&;
+  };
+}

Reply via email to