From: Jeffrey Yasskin Date: Thu, 8 Apr 2010 21:04:54 +0000 (+0000) Subject: Explain that a template needs arguments to make it into a type, for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c173be2aa78cecc6c35445165e59df99d754a1e0;p=clang Explain that a template needs arguments to make it into a type, for variable declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100809 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 92d2f4b50c..82cecc3f4d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -275,6 +275,24 @@ bool Sema::DiagnoseUnknownTypeName(const IdentifierInfo &II, } } + 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(); + 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? diff --git a/test/SemaTemplate/temp_arg.cpp b/test/SemaTemplate/temp_arg.cpp index 80bbda785d..5a4c8fc16f 100644 --- a/test/SemaTemplate/temp_arg.cpp +++ b/test/SemaTemplate/temp_arg.cpp @@ -2,7 +2,7 @@ template class TT> - class A; // expected-note 2 {{template is declared here}} + class A; // expected-note 3 {{template is declared here}} template class X; @@ -10,6 +10,7 @@ A * a1; A *a2; // expected-error{{too many template arguments for class template 'A'}} A *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 foo {};