forked from OSchip/llvm-project
Factor out common code for diagnosing missing template arguments.
In passing, add 'concept' to the list of template kinds in diagnostics. llvm-svn: 330890
This commit is contained in:
parent
2ee366d30e
commit
ecad88d2bb
|
@ -1984,7 +1984,7 @@ def err_auto_not_allowed : Error<
|
|||
"%select{'auto'|'decltype(auto)'|'__auto_type'|"
|
||||
"use of "
|
||||
"%select{class template|function template|variable template|alias template|"
|
||||
"template template parameter|template}2 %3 requires template arguments; "
|
||||
"template template parameter|concept|template}2 %3 requires template arguments; "
|
||||
"argument deduction}0 not allowed "
|
||||
"%select{in function prototype"
|
||||
"|in non-static struct member|in struct member"
|
||||
|
@ -1998,7 +1998,7 @@ def err_auto_not_allowed : Error<
|
|||
def err_dependent_deduced_tst : Error<
|
||||
"typename specifier refers to "
|
||||
"%select{class template|function template|variable template|alias template|"
|
||||
"template template parameter|template}0 member in %1; "
|
||||
"template template parameter|concept|template}0 member in %1; "
|
||||
"argument deduction not allowed here">;
|
||||
def err_auto_not_allowed_var_inst : Error<
|
||||
"'auto' variable template instantiation is not allowed">;
|
||||
|
@ -2078,7 +2078,7 @@ def err_deduced_class_template_compound_type : Error<
|
|||
"deduced class template specialization type">;
|
||||
def err_deduced_non_class_template_specialization_type : Error<
|
||||
"%select{<error>|function template|variable template|alias template|"
|
||||
"template template parameter|template}0 %1 requires template arguments; "
|
||||
"template template parameter|concept|template}0 %1 requires template arguments; "
|
||||
"argument deduction only allowed for class templates">;
|
||||
def err_deduced_class_template_ctor_ambiguous : Error<
|
||||
"ambiguous deduction for template arguments of %0">;
|
||||
|
@ -2106,7 +2106,7 @@ def err_deduction_guide_invalid_specifier : Error<
|
|||
def err_deduction_guide_name_not_class_template : Error<
|
||||
"cannot specify deduction guide for "
|
||||
"%select{<error>|function template|variable template|alias template|"
|
||||
"template template parameter|dependent template name}0 %1">;
|
||||
"template template parameter|concept|dependent template name}0 %1">;
|
||||
def err_deduction_guide_wrong_scope : Error<
|
||||
"deduction guide must be declared in the same scope as template %q0">;
|
||||
def err_deduction_guide_defines_function : Error<
|
||||
|
@ -3991,18 +3991,16 @@ def err_template_member_noparams : Error<
|
|||
"extraneous 'template<>' in declaration of member %0">;
|
||||
def err_template_tag_noparams : Error<
|
||||
"extraneous 'template<>' in declaration of %0 %1">;
|
||||
def err_template_decl_ref : Error<
|
||||
"cannot refer to %select{class|variable}0 template %1 without a template argument list">;
|
||||
|
||||
// C++ Template Argument Lists
|
||||
def err_template_missing_args : Error<
|
||||
"use of "
|
||||
"%select{class template|function template|variable template|alias template|"
|
||||
"template template parameter|template}0 %1 requires template arguments">;
|
||||
"template template parameter|concept|template}0 %1 requires template arguments">;
|
||||
def err_template_arg_list_different_arity : Error<
|
||||
"%select{too few|too many}0 template arguments for "
|
||||
"%select{class template|function template|variable template|alias template|"
|
||||
"template template parameter|template}1 %2">;
|
||||
"template template parameter|concept|template}1 %2">;
|
||||
def note_template_decl_here : Note<"template is declared here">;
|
||||
def err_template_arg_must_be_type : Error<
|
||||
"template argument for template type parameter must be a type">;
|
||||
|
|
|
@ -1820,6 +1820,7 @@ public:
|
|||
VarTemplate,
|
||||
AliasTemplate,
|
||||
TemplateTemplateParam,
|
||||
Concept,
|
||||
DependentTemplate
|
||||
};
|
||||
TemplateNameKindForDiagnostics
|
||||
|
@ -6229,6 +6230,8 @@ public:
|
|||
SourceLocation TemplateLoc,
|
||||
const TemplateArgumentListInfo *TemplateArgs);
|
||||
|
||||
void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc);
|
||||
|
||||
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
|
||||
SourceLocation TemplateKWLoc,
|
||||
LookupResult &R,
|
||||
|
|
|
@ -724,13 +724,7 @@ void Sema::DiagnoseUnknownTypeName(IdentifierInfo *&II,
|
|||
if (isTemplateName(S, SS ? *SS : EmptySS, /*hasTemplateKeyword=*/false,
|
||||
Name, nullptr, true, TemplateResult,
|
||||
MemberOfUnknownSpecialization) == TNK_Type_template) {
|
||||
TemplateName TplName = TemplateResult.get();
|
||||
Diag(IILoc, diag::err_template_missing_args)
|
||||
<< (int)getTemplateNameKindForDiagnostics(TplName) << TplName;
|
||||
if (TemplateDecl *TplDecl = TplName.getAsTemplateDecl()) {
|
||||
Diag(TplDecl->getLocation(), diag::note_template_decl_here)
|
||||
<< TplDecl->getTemplateParameters()->getSourceRange();
|
||||
}
|
||||
diagnoseMissingTemplateArguments(TemplateResult.get(), IILoc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1167,6 +1161,8 @@ Sema::getTemplateNameKindForDiagnostics(TemplateName Name) {
|
|||
return TemplateNameKindForDiagnostics::AliasTemplate;
|
||||
if (isa<TemplateTemplateParmDecl>(TD))
|
||||
return TemplateNameKindForDiagnostics::TemplateTemplateParam;
|
||||
if (isa<ConceptDecl>(TD))
|
||||
return TemplateNameKindForDiagnostics::Concept;
|
||||
return TemplateNameKindForDiagnostics::DependentTemplate;
|
||||
}
|
||||
|
||||
|
|
|
@ -2776,9 +2776,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
|
|||
if (TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) {
|
||||
// Specifically diagnose references to class templates that are missing
|
||||
// a template argument list.
|
||||
Diag(Loc, diag::err_template_decl_ref) << (isa<VarTemplateDecl>(D) ? 1 : 0)
|
||||
<< Template << SS.getRange();
|
||||
Diag(Template->getLocation(), diag::note_template_decl_here);
|
||||
diagnoseMissingTemplateArguments(TemplateName(Template), Loc);
|
||||
return ExprError();
|
||||
}
|
||||
|
||||
|
|
|
@ -920,16 +920,12 @@ getVarTemplateSpecialization(Sema &S, VarTemplateDecl *VarTempl,
|
|||
const TemplateArgumentListInfo *TemplateArgs,
|
||||
const DeclarationNameInfo &MemberNameInfo,
|
||||
SourceLocation TemplateKWLoc) {
|
||||
|
||||
if (!TemplateArgs) {
|
||||
S.Diag(MemberNameInfo.getBeginLoc(), diag::err_template_decl_ref)
|
||||
<< /*Variable template*/ 1 << MemberNameInfo.getName()
|
||||
<< MemberNameInfo.getSourceRange();
|
||||
|
||||
S.Diag(VarTempl->getLocation(), diag::note_template_decl_here);
|
||||
|
||||
S.diagnoseMissingTemplateArguments(TemplateName(VarTempl),
|
||||
MemberNameInfo.getBeginLoc());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DeclResult VDecl = S.CheckVarTemplateId(
|
||||
VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs);
|
||||
if (VDecl.isInvalid())
|
||||
|
|
|
@ -3988,6 +3988,16 @@ Sema::CheckVarTemplateId(const CXXScopeSpec &SS,
|
|||
/*FoundD=*/nullptr, TemplateArgs);
|
||||
}
|
||||
|
||||
void Sema::diagnoseMissingTemplateArguments(TemplateName Name,
|
||||
SourceLocation Loc) {
|
||||
Diag(Loc, diag::err_template_missing_args)
|
||||
<< (int)getTemplateNameKindForDiagnostics(Name) << Name;
|
||||
if (TemplateDecl *TD = Name.getAsTemplateDecl()) {
|
||||
Diag(TD->getLocation(), diag::note_template_decl_here)
|
||||
<< TD->getTemplateParameters()->getSourceRange();
|
||||
}
|
||||
}
|
||||
|
||||
ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
|
||||
SourceLocation TemplateKWLoc,
|
||||
LookupResult &R,
|
||||
|
@ -4208,11 +4218,7 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
|
|||
// is a template without any arguments.
|
||||
SourceRange SR = AL.getSourceRange();
|
||||
TemplateName Name = Arg.getAsTemplateOrTemplatePattern();
|
||||
Diag(SR.getBegin(), diag::err_template_missing_args)
|
||||
<< (int)getTemplateNameKindForDiagnostics(Name) << Name << SR;
|
||||
if (TemplateDecl *Decl = Name.getAsTemplateDecl())
|
||||
Diag(Decl->getLocation(), diag::note_template_decl_here);
|
||||
|
||||
diagnoseMissingTemplateArguments(Name, SR.getEnd());
|
||||
return true;
|
||||
}
|
||||
case TemplateArgument::Expression: {
|
||||
|
|
|
@ -379,4 +379,3 @@ int main() {
|
|||
|
||||
} // end ns PR24473
|
||||
#endif // CPP1Y
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace use_in_top_level_funcs {
|
|||
|
||||
void no_deduce() {
|
||||
// template arguments are not deduced for uses of variable templates.
|
||||
int ipi = pi; // expected-error {{cannot refer to variable template 'pi' without a template argument list}}
|
||||
int icpi = cpi; // expected-error {{cannot refer to variable template 'cpi' without a template argument list}}
|
||||
int ipi = pi; // expected-error {{use of variable template 'pi' requires template arguments}}
|
||||
int icpi = cpi; // expected-error {{use of variable template 'cpi' requires template arguments}}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -465,5 +465,5 @@ auto variadic2 = Variadic<int, int>;
|
|||
|
||||
namespace VexingParse {
|
||||
template <typename> int var; // expected-note {{declared here}}
|
||||
int x(var); // expected-error {{cannot refer to variable template 'var' without a template argument list}}
|
||||
int x(var); // expected-error {{use of variable template 'var' requires template arguments}}
|
||||
}
|
||||
|
|
|
@ -256,12 +256,14 @@ namespace PR31514 {
|
|||
}
|
||||
|
||||
namespace an_alias_template_is_not_a_class_template {
|
||||
template<typename T> using Foo = int; // expected-note 2{{here}}
|
||||
template<typename T> using Foo = int; // expected-note 3{{here}}
|
||||
Foo x; // expected-error {{use of alias template 'Foo' requires template arguments}}
|
||||
Foo<> y; // expected-error {{too few template arguments for alias template 'Foo'}}
|
||||
int z = Foo(); // expected-error {{use of alias template 'Foo' requires template arguments}}
|
||||
|
||||
template<template<typename> class Bar> void f() { // expected-note 2{{here}}
|
||||
template<template<typename> class Bar> void f() { // expected-note 3{{here}}
|
||||
Bar x; // expected-error {{use of template template parameter 'Bar' requires template arguments}}
|
||||
Bar<> y; // expected-error {{too few template arguments for template template parameter 'Bar'}}
|
||||
int z = Bar(); // expected-error {{use of template template parameter 'Bar' requires template arguments}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue