]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: *this capture in const member fn [PR95193].
authorJason Merrill <jason@redhat.com>
Mon, 1 Jun 2020 21:58:57 +0000 (17:58 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 2 Jun 2020 19:00:00 +0000 (15:00 -0400)
Here, the capture proxy for *this is const, but its DECL_VALUE_EXPR is not.
Don't ICE on this; it's a reasonable difference, since in C++ an rvalue of
scalar type does not have cv-qualifiers.

gcc/cp/ChangeLog:

PR c++/95193
* pt.c (tsubst_decl): Relax assert.

gcc/testsuite/ChangeLog:

PR c++/95193
* g++.dg/cpp1z/lambda-this7.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/lambda-this7.C [new file with mode: 0644]

index 907ca879c7319be10c0e1873360178d814e6a920..9c03c5a5bbdeccd414c7390c0708fa74c74a9787 100644 (file)
@@ -14633,7 +14633,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
                         && DECL_BIT_FIELD_TYPE (TREE_OPERAND (ve, 1)) == type)
                  type = TREE_TYPE (ve);
                else
-                 gcc_checking_assert (TREE_TYPE (ve) == type);
+                 gcc_checking_assert (TYPE_MAIN_VARIANT (TREE_TYPE (ve))
+                                      == TYPE_MAIN_VARIANT (type));
                SET_DECL_VALUE_EXPR (r, ve);
              }
            if (CP_DECL_THREAD_LOCAL_P (r)
diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-this7.C b/gcc/testsuite/g++.dg/cpp1z/lambda-this7.C
new file mode 100644 (file)
index 0000000..8137061
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/95193
+// { dg-do compile { target c++17 } }
+
+struct X {
+  void foo() const {
+    auto GL1 = [*this](auto a) {
+    };
+
+    GL1("abc");
+  }
+};