[cfe-commits] r86066 - in /cfe/trunk: lib/Sema/TreeTransform.h test/SemaTemplate/template-id-expr.cpp

Douglas Gregor dgregor at apple.com
Wed Nov 4 15:20:05 PST 2009


Author: dgregor
Date: Wed Nov  4 17:20:05 2009
New Revision: 86066

URL: http://llvm.org/viewvc/llvm-project?rev=86066&view=rev
Log:
When instantiating a MemberExpr, be sure to instantiate the
explicitly-specified template arguments, too!

Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaTemplate/template-id-expr.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=86066&r1=86065&r2=86066&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Nov  4 17:20:05 2009
@@ -941,7 +941,13 @@
                                      NestedNameSpecifier *Qualifier,
                                      SourceRange QualifierRange,
                                      SourceLocation MemberLoc,
-                                     NamedDecl *Member) {
+                                     NamedDecl *Member,
+                                     bool HasExplicitTemplateArgs,
+                                     SourceLocation LAngleLoc,
+                              const TemplateArgumentLoc *ExplicitTemplateArgs,
+                                     unsigned NumExplicitTemplateArgs,
+                                     SourceLocation RAngleLoc,
+                                     NamedDecl *FirstQualifierInScope) {
     if (!Member->getDeclName()) {
       // We have a reference to an unnamed field.
       assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
@@ -963,8 +969,14 @@
                                               isArrow? tok::arrow : tok::period,
                                               MemberLoc,
                                               Member->getDeclName(),
+                                              HasExplicitTemplateArgs,
+                                              LAngleLoc,
+                                              ExplicitTemplateArgs,
+                                              NumExplicitTemplateArgs,
+                                              RAngleLoc,
                                      /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
-                                              &SS);
+                                              &SS,
+                                              FirstQualifierInScope);
   }
 
   /// \brief Build a new binary operator expression.
@@ -3656,9 +3668,20 @@
   if (!getDerived().AlwaysRebuild() &&
       Base.get() == E->getBase() &&
       Qualifier == E->getQualifier() &&
-      Member == E->getMemberDecl())
+      Member == E->getMemberDecl() &&
+      !E->hasExplicitTemplateArgumentList())
     return SemaRef.Owned(E->Retain());
 
+  llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs;
+  if (E->hasExplicitTemplateArgumentList()) {
+    TransArgs.resize(E->getNumTemplateArgs());
+    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
+      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
+                                                 TransArgs[I]))
+        return SemaRef.ExprError();
+    }
+  }
+  
   // FIXME: Bogus source location for the operator
   SourceLocation FakeOperatorLoc
     = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
@@ -3668,7 +3691,13 @@
                                         Qualifier,
                                         E->getQualifierRange(),
                                         E->getMemberLoc(),
-                                        Member);
+                                        Member,
+                                        E->hasExplicitTemplateArgumentList(),
+                                        E->getLAngleLoc(),
+                                        TransArgs.data(),
+                                        TransArgs.size(),
+                                        E->getRAngleLoc(),
+                                        0);
 }
 
 template<typename Derived>

Modified: cfe/trunk/test/SemaTemplate/template-id-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/template-id-expr.cpp?rev=86066&r1=86065&r2=86066&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/template-id-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/template-id-expr.cpp Wed Nov  4 17:20:05 2009
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-
 // PR5336
 template<typename FromCl>
 struct isa_impl_cl {
@@ -12,3 +11,19 @@
 
 class Value;
 void f0(const Value &Val) { isa<Value>(Val); }
+
+// Implicit template-ids.
+template<typename T>
+struct X0 {
+  template<typename U>
+  void f1();
+  
+  template<typename U>
+  void f2(U) {
+    f1<U>();
+  }
+};
+
+void test_X0_int(X0<int> xi, float f) {
+  xi.f2(f);
+}





More information about the cfe-commits mailing list