From ef4a2a2b546279d53790013f9bfd51064fe26c54 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 22 Jun 2010 02:41:05 +0000 Subject: [PATCH] Apply array-to-pointer decay when instantiating a MemberExpr. Fixes PR7405, patch by Kyle Lippincott! llvm-svn: 106523 --- clang/lib/Sema/TreeTransform.h | 8 +++--- .../SemaTemplate/array-to-pointer-decay.cpp | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaTemplate/array-to-pointer-decay.cpp diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 6032244a15c2..d959f1c22e77 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1174,7 +1174,9 @@ public: SS.setScopeRep(Qualifier); } - QualType BaseType = ((Expr*) Base.get())->getType(); + Expr *BaseExpr = Base.takeAs(); + 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/clang/test/SemaTemplate/array-to-pointer-decay.cpp b/clang/test/SemaTemplate/array-to-pointer-decay.cpp new file mode 100644 index 000000000000..072c0e52edc6 --- /dev/null +++ b/clang/test/SemaTemplate/array-to-pointer-decay.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct mystruct { + int member; +}; + +template +int foo() { + mystruct s[1]; + return s->member; +} + +int main() { + foo<1>(); +} + +// PR7405 +struct hb_sanitize_context_t { + int start; +}; +template static bool sanitize() { + hb_sanitize_context_t c[1]; + return !c->start; +} +bool closure = sanitize();