summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-19 00:01:19 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-19 00:01:19 +0000
commit7a77a6bcf9a9b9ae68afe48313d6f78102dcff39 (patch)
tree72422978ed34573cd9d5368ebacb88ffdf7505cc /clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
parentb9509c55fe2950fc217daf30bc90f82635dc231f (diff)
downloadbcm5719-llvm-7a77a6bcf9a9b9ae68afe48313d6f78102dcff39.tar.gz
bcm5719-llvm-7a77a6bcf9a9b9ae68afe48313d6f78102dcff39.zip
Template instantiation for array subscript expressions. This was far
easier than expected because of the limitation that subscript operators must be member functions. llvm-svn: 72076
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiateExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateExpr.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
index c6ce6f46938..41df7aba29e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -45,6 +45,7 @@ namespace {
OwningExprResult VisitDeclRefExpr(DeclRefExpr *E);
OwningExprResult VisitParenExpr(ParenExpr *E);
OwningExprResult VisitUnaryOperator(UnaryOperator *E);
+ OwningExprResult VisitArraySubscriptExpr(ArraySubscriptExpr *E);
OwningExprResult VisitBinaryOperator(BinaryOperator *E);
OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
OwningExprResult VisitCXXConditionDeclExpr(CXXConditionDeclExpr *E);
@@ -173,6 +174,36 @@ TemplateExprInstantiator::VisitUnaryOperator(UnaryOperator *E) {
}
Sema::OwningExprResult
+TemplateExprInstantiator::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
+ Sema::OwningExprResult LHS = Visit(E->getLHS());
+ if (LHS.isInvalid())
+ return SemaRef.ExprError();
+
+ Sema::OwningExprResult RHS = Visit(E->getRHS());
+ if (RHS.isInvalid())
+ return SemaRef.ExprError();
+
+ // Since the overloaded array-subscript operator (operator[]) can
+ // only be a member function, we can make several simplifying
+ // assumptions here:
+ // 1) Normal name lookup (from the current scope) will not ever
+ // find any declarations of operator[] that won't also be found be
+ // member operator lookup, so it is safe to pass a NULL Scope
+ // during the instantiation to avoid the lookup entirely.
+ //
+ // 2) Neither normal name lookup nor argument-dependent lookup at
+ // template definition time will find any operators that won't be
+ // found at template instantiation time, so we do not need to
+ // cache the results of name lookup as we do for the binary
+ // operators.
+ SourceLocation LLocFake = ((Expr*)LHS.get())->getSourceRange().getBegin();
+ return SemaRef.ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
+ /*FIXME:*/LLocFake,
+ move(RHS),
+ E->getRBracketLoc());
+}
+
+Sema::OwningExprResult
TemplateExprInstantiator::VisitBinaryOperator(BinaryOperator *E) {
Sema::OwningExprResult LHS = Visit(E->getLHS());
if (LHS.isInvalid())
OpenPOWER on IntegriCloud