royjacobson updated this revision to Diff 505624.
royjacobson added a comment.

rebase + release notes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146168/new/

https://reviews.llvm.org/D146168

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===================================================================
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@
   void foo() const { //expected-note{{const}}
 
     auto L = [*this]() mutable {
-      static_assert(is_same<decltype(this), X *>);
-      ++d;
+      static_assert(is_same<decltype(this), const X *>);
       auto M = [this] {
-        static_assert(is_same<decltype(this), X *>);
-        ++d;
+        static_assert(is_same<decltype(this), const X *>);
         auto N = [] {
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const X *>);
         };
       };
     };
@@ -108,9 +106,9 @@
         };
       };
       auto M2 = [*this]() mutable {
-        static_assert(is_same<decltype(this), X *>);
+        static_assert(is_same<decltype(this), const X *>);
         auto N = [] {
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const X *>);
         };
       };
     };
@@ -126,9 +124,9 @@
       };
 
       auto M2 = [*this](auto a) mutable {
-        static_assert(is_same<decltype(this), X *>);
+        static_assert(is_same<decltype(this), const X *>);
         auto N = [](auto b) {
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const X *>);
         };
         return N;
       };
@@ -143,13 +141,11 @@
       ++d; //expected-error{{cannot assign}}
     };
     auto GL = [*this](auto a) mutable {
-      static_assert(is_same<decltype(this), X *>);
-      ++d;
+      static_assert(is_same<decltype(this), const X *>);
       auto M = [this](auto b) {
-        static_assert(is_same<decltype(this), X *>);
-        ++d;
+        static_assert(is_same<decltype(this), const X *>);
         auto N = [](auto c) {
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const X *>);
         };
         N(3.14);
       };
@@ -161,21 +157,21 @@
     auto L = [this]() {
       static_assert(is_same<decltype(this), const volatile X *>);
       auto M = [*this]() mutable {
-        static_assert(is_same<decltype(this), X *>);
+        static_assert(is_same<decltype(this), const volatile X *>);
         auto N = [this] {
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const volatile X *>);
           auto M = [] {
-            static_assert(is_same<decltype(this), X *>);
+            static_assert(is_same<decltype(this), const volatile X *>);
           };
         };
         auto N2 = [*this] {
-          static_assert(is_same<decltype(this), const X *>);
+          static_assert(is_same<decltype(this), const volatile X *>);
         };
       };
       auto M2 = [*this]() {
-        static_assert(is_same<decltype(this), const X *>);
+        static_assert(is_same<decltype(this), const volatile X *>);
         auto N = [this] {
-          static_assert(is_same<decltype(this), const X *>);
+          static_assert(is_same<decltype(this), const volatile X *>);
         };
       };
     };
@@ -190,14 +186,13 @@
     auto L = [*this]() mutable {
       auto M = [=](auto a) {
         auto N = [this] {
-          ++d;
-          static_assert(is_same<decltype(this), X *>);
+          static_assert(is_same<decltype(this), const X *>);
           auto O = [*this] {
             static_assert(is_same<decltype(this), const X *>);
           };
         };
         N();
-        static_assert(is_same<decltype(this), X *>);
+        static_assert(is_same<decltype(this), const X *>);
       };
       return M;
     };
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,8 +1135,7 @@
     auto C = CurLSI->getCXXThisCapture();
 
     if (C.isCopyCapture()) {
-      ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-      if (!CurLSI->Mutable)
+        if (!CurLSI->Mutable)
         ClassType.addConst();
       return ASTCtx.getPointerType(ClassType);
     }
@@ -1175,7 +1174,6 @@
     while (Closure &&
            IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
       if (IsByCopyCapture) {
-        ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
         if (IsConstCapture)
           ClassType.addConst();
         return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@
 
     // The type of the corresponding data member (not a 'this' pointer if 'by
     // copy').
-    QualType CaptureType = ThisTy;
-    if (ByCopy) {
-      // If we are capturing the object referred to by '*this' by copy, ignore
-      // any cv qualifiers inherited from the type of the member function for
-      // the type of the closure-type's corresponding data member and any use
-      // of 'this'.
-      CaptureType = ThisTy->getPointeeType();
-      CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-    }
+    QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
 
     bool isNested = NumCapturingClosures > 1;
     CSI->addThisCapture(isNested, Loc, CaptureType, ByCopy);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,9 @@
 - Fix an issue about ``decltype`` in the members of class templates derived from
   templates with related parameters.
   (`#58674 <https://github.com/llvm/llvm-project/issues/58674>`_)
+- Stop stripping CV qualifiers from the type of ``this`` when capturing it by value in
+  a lambda.
+  (`#50866 <https://github.com/llvm/llvm-project/issues/50866>`_)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to