[cfe-commits] r128387 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/Parser.h lib/Parse/ParseExprCXX.cpp lib/Parse/Parser.cpp test/FixIt/fixit.cpp test/Parser/MicrosoftExtensions.cpp

Francois Pichet pichet2000 at gmail.com
Sun Mar 27 12:41:35 PDT 2011


Author: fpichet
Date: Sun Mar 27 14:41:34 2011
New Revision: 128387

URL: http://llvm.org/viewvc/llvm-project?rev=128387&view=rev
Log:
Improve recovery (error + fix-it) when parsing type dependent template name without the "template" keyword.

For example:
   typename C1<T>:: /*template*/ Iterator<0> pos; 

Also the error is downgraded to an ExtWarn in Microsoft mode.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/test/FixIt/fixit.cpp
    cfe/trunk/test/Parser/MicrosoftExtensions.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sun Mar 27 14:41:34 2011
@@ -370,6 +370,8 @@
 
 def err_missing_dependent_template_keyword : Error<
   "use 'template' keyword to treat '%0' as a dependent template name">;
+def war_missing_dependent_template_keyword : ExtWarn<
+  "use 'template' keyword to treat '%0' as a dependent template name">;
 
 def warn_static_inline_explicit_inst_ignored : Warning<
   "ignoring '%select{static|inline}0' keyword on explicit template "

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Mar 27 14:41:34 2011
@@ -1108,7 +1108,8 @@
   bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
                                       ParsedType ObjectType,
                                       bool EnteringContext,
-                                      bool *MayBePseudoDestructor = 0);
+                                      bool *MayBePseudoDestructor = 0,
+                                      bool IsTypename = false);
 
   //===--------------------------------------------------------------------===//
   // C++ 5.2p1: C++ Casts

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sun Mar 27 14:41:34 2011
@@ -60,7 +60,8 @@
 bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
                                             ParsedType ObjectType,
                                             bool EnteringContext,
-                                            bool *MayBePseudoDestructor) {
+                                            bool *MayBePseudoDestructor,
+                                            bool IsTypename) {
   assert(getLang().CPlusPlus &&
          "Call sites of this function should be guarded by checking for C++");
 
@@ -314,12 +315,16 @@
       } 
       
       if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) && 
-          IsTemplateArgumentList(1)) {
+          (IsTypename || IsTemplateArgumentList(1))) {
         // We have something like t::getAs<T>, where getAs is a 
         // member of an unknown specialization. However, this will only
         // parse correctly as a template, so suggest the keyword 'template'
         // before 'getAs' and treat this as a dependent template name.
-        Diag(Tok.getLocation(), diag::err_missing_dependent_template_keyword)
+        unsigned DiagID = diag::err_missing_dependent_template_keyword;
+        if (getLang().Microsoft)
+          DiagID = diag::war_missing_dependent_template_keyword;
+        
+        Diag(Tok.getLocation(), DiagID)
           << II.getName()
           << FixItHint::CreateInsertion(Tok.getLocation(), "template ");
         

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sun Mar 27 14:41:34 2011
@@ -1037,7 +1037,8 @@
     //            simple-template-id
     SourceLocation TypenameLoc = ConsumeToken();
     CXXScopeSpec SS;
-    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(), false))
+    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(), false,
+                                       0, /*IsTypename*/true))
       return true;
     if (!SS.isSet()) {
       Diag(Tok.getLocation(), diag::err_expected_qualified_after_typename);

Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Sun Mar 27 14:41:34 2011
@@ -78,3 +78,22 @@
 }
 }
 
+template <class A>
+class F1 {
+public:
+  template <int B>
+  class Iterator {
+  };
+};
+ 
+template<class T>
+class F2  {
+  typename F1<T>:: /*template*/  Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
+};
+
+template <class T>
+void f(){
+  typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
+}
+
+

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=128387&r1=128386&r2=128387&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Sun Mar 27 14:41:34 2011
@@ -111,3 +111,27 @@
     }
     return *this;
 }
+
+template <class A>
+class C1 {
+public:
+  template <int B>
+  class Iterator {
+  };
+};
+ 
+template<class T>
+class C2  {
+  typename C1<T>:: /*template*/  Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
+};
+
+template <class T>
+void f(){
+  typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
+}
+
+int main() {
+  f<int>();
+}
+
+





More information about the cfe-commits mailing list