From: Douglas Gregor Date: Wed, 14 Oct 2009 23:50:59 +0000 (+0000) Subject: CheckTemplateSpecializationScope isn't going to be used for explicit X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9302da67eabe2e9ad27433994b6727d670839476;p=clang CheckTemplateSpecializationScope isn't going to be used for explicit instantiations, since the requirements are too different from those for template specializations. Simplify it slightly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84156 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 4845314743..b1222a3f84 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -936,18 +936,15 @@ def err_template_arg_extra_parens : Error< // C++ template specialization def err_template_spec_unknown_kind : Error< - "can only provide an explicit %select{||specialization|" - "instantiation|instantiation}0 for a class template, function template, or " - "a member function, static data member, or member class of a class template">; + "can only provide an explicit specialization for a class template, function " + "template, or a member function, static data member, or member class of a " + "class template">; def note_specialized_entity : Note< - "explicitly %select{||specialized|instantiated|instantiated}0 " - "declaration is here">; + "explicitly specialized declaration is here">; def err_template_spec_decl_function_scope : Error< - "explicit %select{||specialization|instantiation|" - "instantiation}0 of %1 in function scope">; + "explicit specialization of %0 in function scope">; def err_template_spec_decl_class_scope : Error< - "explicit %select{||specialization|instantiation|" - "instantiation}0 of %1 in class scope">; + "explicit specialization of %0 in class scope">; def err_template_spec_decl_out_of_scope_global : Error< "%select{class template|class template partial|function template|member " "function|static data member|member class}0 specialization of %1 must " diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 22c0e2975b..ab0bbe081d 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2398,12 +2398,11 @@ static TemplateSpecializationKind getTemplateSpecializationKind(NamedDecl *D) { return TSK_Undeclared; } -/// \brief Check whether a specialization or explicit instantiation is -/// well-formed in the current context. +/// \brief Check whether a specialization is well-formed in the current +/// context. /// -/// This routine determines whether a template specialization or -/// explicit instantiation can be declared in the current context -/// (C++ [temp.expl.spec]p2, C++0x [temp.explicit]p2). +/// This routine determines whether a template specialization can be declared +/// in the current context (C++ [temp.expl.spec]p2). /// /// \param S the semantic analysis object for which this check is being /// performed. @@ -2421,17 +2420,13 @@ static TemplateSpecializationKind getTemplateSpecializationKind(NamedDecl *D) { /// \param IsPartialSpecialization whether this is a partial specialization of /// a class template. /// -/// \param TSK the kind of specialization or explicit instantiation being -/// performed. -/// /// \returns true if there was an error that we cannot recover from, false /// otherwise. static bool CheckTemplateSpecializationScope(Sema &S, NamedDecl *Specialized, NamedDecl *PrevDecl, SourceLocation Loc, - bool IsPartialSpecialization, - TemplateSpecializationKind TSK) { + bool IsPartialSpecialization) { // Keep these "kind" numbers in sync with the %select statements in the // various diagnostics emitted by this routine. int EntityKind = 0; @@ -2449,8 +2444,8 @@ static bool CheckTemplateSpecializationScope(Sema &S, else if (isa(Specialized)) EntityKind = 5; else { - S.Diag(Loc, diag::err_template_spec_unknown_kind) << TSK; - S.Diag(Specialized->getLocation(), diag::note_specialized_entity) << TSK; + S.Diag(Loc, diag::err_template_spec_unknown_kind); + S.Diag(Specialized->getLocation(), diag::note_specialized_entity); return true; } @@ -2469,13 +2464,13 @@ static bool CheckTemplateSpecializationScope(Sema &S, // declared. if (S.CurContext->getLookupContext()->isFunctionOrMethod()) { S.Diag(Loc, diag::err_template_spec_decl_function_scope) - << TSK << Specialized; + << Specialized; return true; } if (S.CurContext->isRecord() && !IsPartialSpecialization) { S.Diag(Loc, diag::err_template_spec_decl_class_scope) - << TSK << Specialized; + << Specialized; return true; } @@ -2487,43 +2482,36 @@ static bool CheckTemplateSpecializationScope(Sema &S, DeclContext *SpecializedContext = Specialized->getDeclContext()->getEnclosingNamespaceContext(); DeclContext *DC = S.CurContext->getEnclosingNamespaceContext(); - if (TSK == TSK_ExplicitSpecialization) { - if ((!PrevDecl || - getTemplateSpecializationKind(PrevDecl) == TSK_Undeclared || - getTemplateSpecializationKind(PrevDecl) == TSK_ImplicitInstantiation)){ - // There is no prior declaration of this entity, so this - // specialization must be in the same context as the template - // itself. - if (!DC->Equals(SpecializedContext)) { - if (isa(SpecializedContext)) - S.Diag(Loc, diag::err_template_spec_decl_out_of_scope_global) - << EntityKind << Specialized; - else if (isa(SpecializedContext)) - S.Diag(Loc, diag::err_template_spec_decl_out_of_scope) - << EntityKind << Specialized - << cast(SpecializedContext); - - S.Diag(Specialized->getLocation(), diag::note_specialized_entity) - << TSK; - ComplainedAboutScope = true; - } + if ((!PrevDecl || + getTemplateSpecializationKind(PrevDecl) == TSK_Undeclared || + getTemplateSpecializationKind(PrevDecl) == TSK_ImplicitInstantiation)){ + // There is no prior declaration of this entity, so this + // specialization must be in the same context as the template + // itself. + if (!DC->Equals(SpecializedContext)) { + if (isa(SpecializedContext)) + S.Diag(Loc, diag::err_template_spec_decl_out_of_scope_global) + << EntityKind << Specialized; + else if (isa(SpecializedContext)) + S.Diag(Loc, diag::err_template_spec_decl_out_of_scope) + << EntityKind << Specialized + << cast(SpecializedContext); + + S.Diag(Specialized->getLocation(), diag::note_specialized_entity); + ComplainedAboutScope = true; } } // Make sure that this redeclaration (or definition) occurs in an enclosing - // namespace. We perform this check for explicit specializations and, in - // C++0x, for explicit instantiations as well (per DR275). - // FIXME: -Wc++0x should make these warnings. + // namespace. // Note that HandleDeclarator() performs this check for explicit // specializations of function templates, static data members, and member // functions, so we skip the check here for those kinds of entities. // FIXME: HandleDeclarator's diagnostics aren't quite as good, though. // Should we refactor that check, so that it occurs later? if (!ComplainedAboutScope && !DC->Encloses(SpecializedContext) && - ((TSK == TSK_ExplicitSpecialization && - !(isa(Specialized) || isa(Specialized) || - isa(Specialized))) || - S.getLangOptions().CPlusPlus0x)) { + !(isa(Specialized) || isa(Specialized) || + isa(Specialized))) { if (isa(SpecializedContext)) S.Diag(Loc, diag::err_template_spec_redecl_global_scope) << EntityKind << Specialized; @@ -2532,7 +2520,7 @@ static bool CheckTemplateSpecializationScope(Sema &S, << EntityKind << Specialized << cast(SpecializedContext); - S.Diag(Specialized->getLocation(), diag::note_specialized_entity) << TSK; + S.Diag(Specialized->getLocation(), diag::note_specialized_entity); } // FIXME: check for specialization-after-instantiation errors and such. @@ -2835,8 +2823,8 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, // the current scope. if (TUK != TUK_Friend && CheckTemplateSpecializationScope(*this, ClassTemplate, PrevDecl, - TemplateNameLoc, isPartialSpecialization, - TSK_ExplicitSpecialization)) + TemplateNameLoc, + isPartialSpecialization)) return true; // The canonical type @@ -3146,7 +3134,7 @@ Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD, if (CheckTemplateSpecializationScope(*this, Specialization->getPrimaryTemplate(), Specialization, FD->getLocation(), - false, TSK_ExplicitSpecialization)) + false)) return true; // C++ [temp.expl.spec]p6: @@ -3273,7 +3261,7 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, NamedDecl *&PrevDecl) { if (CheckTemplateSpecializationScope(*this, InstantiatedFrom, Instantiation, Member->getLocation(), - false, TSK_ExplicitSpecialization)) + false)) return true; // Note that this is an explicit instantiation of a member.