[cfe-commits] r100809 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaTemplate/temp_arg.cpp

Jeffrey Yasskin jyasskin at google.com
Thu Apr 8 14:04:54 PDT 2010


Author: jyasskin
Date: Thu Apr  8 16:04:54 2010
New Revision: 100809

URL: http://llvm.org/viewvc/llvm-project?rev=100809&view=rev
Log:
Explain that a template needs arguments to make it into a type, for
variable declarations.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaTemplate/temp_arg.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=100809&r1=100808&r2=100809&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr  8 16:04:54 2010
@@ -275,6 +275,24 @@
     }
   }
 
+  if (getLangOptions().CPlusPlus) {
+    // See if II is a class template that the user forgot to pass arguments to.
+    UnqualifiedId Name;
+    Name.setIdentifier(&II, IILoc);
+    CXXScopeSpec EmptySS;
+    TemplateTy TemplateResult;
+    if (isTemplateName(S, SS ? *SS : EmptySS, Name, 0, true, TemplateResult)
+        == TNK_Type_template) {
+      TemplateName TplName = TemplateResult.getAsVal<TemplateName>();
+      Diag(IILoc, diag::err_template_missing_args) << TplName;
+      if (TemplateDecl *TplDecl = TplName.getAsTemplateDecl()) {
+        Diag(TplDecl->getLocation(), diag::note_template_decl_here)
+          << TplDecl->getTemplateParameters()->getSourceRange();
+      }
+      return true;
+    }
+  }
+
   // FIXME: Should we move the logic that tries to recover from a missing tag
   // (struct, union, enum) from Parser::ParseImplicitInt here, instead?
   

Modified: cfe/trunk/test/SemaTemplate/temp_arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg.cpp?rev=100809&r1=100808&r2=100809&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg.cpp Thu Apr  8 16:04:54 2010
@@ -2,7 +2,7 @@
 template<typename T, 
          int I, 
          template<typename> class TT>
-  class A; // expected-note 2 {{template is declared here}}
+  class A; // expected-note 3 {{template is declared here}}
 
 template<typename> class X;
 
@@ -10,6 +10,7 @@
 
 A<float, 1, X, double> *a2; // expected-error{{too many template arguments for class template 'A'}}
 A<float, 1> *a3; // expected-error{{too few template arguments for class template 'A'}}
+A a3; // expected-error{{use of class template A requires template arguments}}
 
 namespace test0 {
   template <class t> class foo {};





More information about the cfe-commits mailing list