[cfe-commits] r89512 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTemplate.cpp lib/Sema/Sema.h lib/Sema/SemaTemplate.cpp lib/Sema/TreeTransform.h test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp

Douglas Gregor dgregor at apple.com
Fri Nov 20 15:39:24 PST 2009


Author: dgregor
Date: Fri Nov 20 17:39:24 2009
New Revision: 89512

URL: http://llvm.org/viewvc/llvm-project?rev=89512&view=rev
Log:
Cope with extraneous "template" keyword when providing an out-of-line
definition of a member template (or a member thereof). Fixes PR5566.

Modified:
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/lib/Parse/ParseTemplate.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Nov 20 17:39:24 2009
@@ -1685,10 +1685,14 @@
   /// \param ObjectType if this dependent template name occurs in the
   /// context of a member access expression, the type of the object being
   /// accessed.
+  ///
+  /// \param EnteringContext whether we are entering the context of this
+  /// template.
   virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
                                                 const CXXScopeSpec &SS,
                                                 UnqualifiedId &Name,
-                                                TypeTy *ObjectType) {
+                                                TypeTy *ObjectType,
+                                                bool EnteringContext) {
     return TemplateTy();
   }
 

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Fri Nov 20 17:39:24 2009
@@ -148,7 +148,7 @@
       TPA.Commit();
       TemplateTy Template
         = Actions.ActOnDependentTemplateName(TemplateKWLoc, SS, TemplateName,
-                                             ObjectType);
+                                             ObjectType, EnteringContext);
       if (!Template)
         break;
       if (AnnotateTemplateIdToken(Template, TNK_Dependent_template_name,
@@ -774,7 +774,8 @@
     TemplateName.setIdentifier(Name, NameLoc);
     if (ObjectType) {
       Template = Actions.ActOnDependentTemplateName(SourceLocation(), SS, 
-                                                    TemplateName, ObjectType);
+                                                    TemplateName, ObjectType,
+                                                    EnteringContext);
       TNK = TNK_Dependent_template_name;
       if (!Template.get())
         return true;

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Nov 20 17:39:24 2009
@@ -851,7 +851,8 @@
       if (isEndOfTemplateArgument(Tok)) {
         TemplateTy Template
         = Actions.ActOnDependentTemplateName(TemplateLoc, SS, Name, 
-                                             /*ObjectType=*/0);
+                                             /*ObjectType=*/0,
+                                             /*EnteringContext=*/false);
         if (Template.get())
           return ParsedTemplateArgument(SS, Template, Name.StartLocation);
       }

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Nov 20 17:39:24 2009
@@ -2293,7 +2293,8 @@
   virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
                                                 const CXXScopeSpec &SS,
                                                 UnqualifiedId &Name,
-                                                TypeTy *ObjectType);
+                                                TypeTy *ObjectType,
+                                                bool EnteringContext);
 
   bool CheckClassTemplatePartialSpecializationArgs(
                                         TemplateParameterList *TemplateParams,

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Nov 20 17:39:24 2009
@@ -1381,10 +1381,11 @@
 Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
                                  const CXXScopeSpec &SS,
                                  UnqualifiedId &Name,
-                                 TypeTy *ObjectType) {
+                                 TypeTy *ObjectType,
+                                 bool EnteringContext) {
   if ((ObjectType &&
        computeDeclContext(QualType::getFromOpaquePtr(ObjectType))) ||
-      (SS.isSet() && computeDeclContext(SS, false))) {
+      (SS.isSet() && computeDeclContext(SS, EnteringContext))) {
     // C++0x [temp.names]p5:
     //   If a name prefixed by the keyword template is not the name of
     //   a template, the program is ill-formed. [Note: the keyword
@@ -1403,7 +1404,7 @@
     // rules, even in C++03 mode, retroactively applying the DR.
     TemplateTy Template;
     TemplateNameKind TNK = isTemplateName(0, SS, Name, ObjectType,
-                                          false, Template);
+                                          EnteringContext, Template);
     if (TNK == TNK_Non_template) {
       Diag(Name.getSourceRange().getBegin(), 
            diag::err_template_kw_refers_to_non_template)

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

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Nov 20 17:39:24 2009
@@ -5349,7 +5349,8 @@
                                       /*FIXME:*/getDerived().getBaseLocation(),
                                               SS,
                                               Name,
-                                              ObjectType.getAsOpaquePtr())
+                                              ObjectType.getAsOpaquePtr(),
+                                              /*EnteringContext=*/false)
            .template getAsVal<TemplateName>();
 }
 
@@ -5369,7 +5370,8 @@
                                        /*FIXME:*/getDerived().getBaseLocation(),
                                               SS,
                                               Name,
-                                              ObjectType.getAsOpaquePtr())
+                                              ObjectType.getAsOpaquePtr(),
+                                              /*EnteringContext=*/false)
            .template getAsVal<TemplateName>();
 }
   

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp Fri Nov 20 17:39:24 2009
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-
 template<typename T, int N>
 struct A;
 

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp?rev=89512&r1=89511&r2=89512&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp Fri Nov 20 17:39:24 2009
@@ -66,3 +66,14 @@
 
 namespace N { template <class X> class A {void a();}; }
 namespace N { template <class X> void A<X>::a() {} }
+
+// PR5566
+template<typename T>
+struct X1 { 
+  template<typename U>
+  struct B { void f(); };
+};
+
+template<typename T>
+template<typename U>
+void X1<T>::template B<U>::f() { }





More information about the cfe-commits mailing list