]> granicus.if.org Git - clang/commitdiff
Apply array-to-pointer decay when instantiating a MemberExpr. Fixes
authorDouglas Gregor <dgregor@apple.com>
Tue, 22 Jun 2010 02:41:05 +0000 (02:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 22 Jun 2010 02:41:05 +0000 (02:41 +0000)
PR7405, patch by Kyle Lippincott!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106523 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/TreeTransform.h
test/SemaTemplate/array-to-pointer-decay.cpp [new file with mode: 0644]

index 6032244a15c2444a1633603e64ff8c1449d4a08f..d959f1c22e7796595bf66da7c0c7cc2b6387cd88 100644 (file)
@@ -1174,7 +1174,9 @@ public:
       SS.setScopeRep(Qualifier);
     }
 
-    QualType BaseType = ((Expr*) Base.get())->getType();
+    Expr *BaseExpr = Base.takeAs<Expr>();
+    getSema().DefaultFunctionArrayConversion(BaseExpr);
+    QualType BaseType = BaseExpr->getType();
 
     // FIXME: this involves duplicating earlier analysis in a lot of
     // cases; we should avoid this when possible.
@@ -1183,8 +1185,8 @@ public:
     R.addDecl(FoundDecl);
     R.resolveKind();
 
-    return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
-                                              OpLoc, isArrow,
+    return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
+                                              BaseType, OpLoc, isArrow,
                                               SS, FirstQualifierInScope,
                                               R, ExplicitTemplateArgs);
   }
diff --git a/test/SemaTemplate/array-to-pointer-decay.cpp b/test/SemaTemplate/array-to-pointer-decay.cpp
new file mode 100644 (file)
index 0000000..072c0e5
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct mystruct {
+  int  member;
+};
+
+template <int i>
+int foo() {
+  mystruct s[1];
+  return s->member;
+}
+
+int main() {
+  foo<1>();
+}
+
+// PR7405
+struct hb_sanitize_context_t {
+  int start;
+};
+template <typename Type> static bool sanitize() {
+  hb_sanitize_context_t c[1];
+  return !c->start;
+}
+bool closure = sanitize<int>();