r360387 - Remember to decay arrays to pointers before checking whether the

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu May 9 15:22:48 PDT 2019


Author: rsmith
Date: Thu May  9 15:22:48 2019
New Revision: 360387

URL: http://llvm.org/viewvc/llvm-project?rev=360387&view=rev
Log:
Remember to decay arrays to pointers before checking whether the
left-hand side of an -> operator is a pointer to class type.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/Parser/cxx-class.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=360387&r1=360386&r2=360387&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu May  9 15:22:48 2019
@@ -6790,9 +6790,12 @@ ExprResult Sema::ActOnStartCXXMemberRefe
       FirstIteration = false;
     }
 
-    if (OpKind == tok::arrow &&
-        (BaseType->isPointerType() || BaseType->isObjCObjectPointerType()))
-      BaseType = BaseType->getPointeeType();
+    if (OpKind == tok::arrow) {
+      if (BaseType->isPointerType())
+        BaseType = BaseType->getPointeeType();
+      else if (auto *AT = Context.getAsArrayType(BaseType))
+        BaseType = AT->getElementType();
+    }
   }
 
   // Objective-C properties allow "." access on Objective-C pointer types,

Modified: cfe/trunk/test/Parser/cxx-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-class.cpp?rev=360387&r1=360386&r2=360387&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-class.cpp (original)
+++ cfe/trunk/test/Parser/cxx-class.cpp Thu May  9 15:22:48 2019
@@ -283,6 +283,19 @@ struct C {} decltype(D())::c; // expecte
 #endif
 }
 
+namespace ArrayMemberAccess {
+  struct A {
+    int x;
+    template<typename T> int f() const;
+  };
+  void f(const A (&a)[]) {
+    // OK: not a template-id.
+    bool cond = a->x < 10 && a->x > 0;
+    // OK: a template-id.
+    a->f<int>();
+  }
+}
+
 // PR11109 must appear at the end of the source file
 class pr11109r3 { // expected-note{{to match this '{'}}
   public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}




More information about the cfe-commits mailing list