]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: decltype of capture proxy of ref [PR115504]
authorPatrick Palka <ppalka@redhat.com>
Wed, 26 Jun 2024 00:07:15 +0000 (20:07 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 26 Jun 2024 00:07:15 +0000 (20:07 -0400)
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 <jason@redhat.com>
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp1y/decltype-auto8.C [new file with mode: 0644]

index 8e3e4e23b72df613302090a269beb17636523ea4..44de4c9a5293bd4d47c3c3498ae7d79e5cf807af 100644 (file)
@@ -12071,7 +12071,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 (file)
index 0000000..55135ce
--- /dev/null
@@ -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&;
+  };
+}