diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 14 | ||||
| -rw-r--r-- | clang/include/clang/Sema/Sema.h | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprMember.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 16 | ||||
| -rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | 1 | ||||
| -rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/alias-templates.cpp | 6 | 
9 files changed, 34 insertions, 36 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index c1ee929e236..04840b690d7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 485c537949b..9897f0f23cd 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -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, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 1bcc9329e4c..0c412d373cb 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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;  } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b4d1eb0e0ce..6f2800ea27d 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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();    } diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 01a13c4b357..775008ea807 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -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()) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 239f3617ca9..442a8ec6805 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -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: { diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index 04c4429368f..6471cd84183 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -379,4 +379,3 @@ int main() {  } // end ns PR24473  #endif // CPP1Y - diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index ecd9593c675..ddc9c8a6b25 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -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}}  } diff --git a/clang/test/SemaTemplate/alias-templates.cpp b/clang/test/SemaTemplate/alias-templates.cpp index 3b7548d169b..240a6eeff2e 100644 --- a/clang/test/SemaTemplate/alias-templates.cpp +++ b/clang/test/SemaTemplate/alias-templates.cpp @@ -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}}    }  }  | 

