[PATCH] D58659: [Sema] Fix assertion when `auto` parameter in lambda has an attribute.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 29 11:45:40 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL357298: [Sema] Fix assertion when `auto` parameter in lambda has an attribute. (authored by vsapsai, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58659?vs=188283&id=192878#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58659

Files:
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaCXX/auto-cxx0x.cpp


Index: cfe/trunk/lib/Sema/SemaType.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -255,6 +255,23 @@
       return T;
     }
 
+    /// Completely replace the \c auto in \p TypeWithAuto by
+    /// \p Replacement. Also replace \p TypeWithAuto in \c TypeAttrPair if
+    /// necessary.
+    QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement) {
+      QualType T = sema.ReplaceAutoType(TypeWithAuto, Replacement);
+      if (auto *AttrTy = TypeWithAuto->getAs<AttributedType>()) {
+        // Attributed type still should be an attributed type after replacement.
+        auto *NewAttrTy = cast<AttributedType>(T.getTypePtr());
+        for (TypeAttrPair &A : AttrsForTypes) {
+          if (A.first == AttrTy)
+            A.first = NewAttrTy;
+        }
+        AttrsForTypesSorted = false;
+      }
+      return T;
+    }
+
     /// Extract and remove the Attr* for a given attributed type.
     const Attr *takeAttrForAttributedType(const AttributedType *AT) {
       if (!AttrsForTypesSorted) {
@@ -2938,7 +2955,7 @@
         // template type parameter.
         // FIXME: Retain some type sugar to indicate that this was written
         // as 'auto'.
-        T = SemaRef.ReplaceAutoType(
+        T = state.ReplaceAutoType(
             T, QualType(CorrespondingTemplateParam->getTypeForDecl(), 0));
       }
       break;
Index: cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
+++ cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
@@ -15,3 +15,11 @@
   // expected-error at -2 {{'auto' not allowed in lambda parameter}}
 #endif
 }
+
+void rdar47689465() {
+  int x = 0;
+  [](auto __attribute__((noderef)) *){}(&x);
+#if __cplusplus == 201103L
+  // expected-error at -2 {{'auto' not allowed in lambda parameter}}
+#endif
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58659.192878.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190329/47bcd463/attachment-0001.bin>


More information about the cfe-commits mailing list