From: Richard Smith Date: Thu, 8 Jun 2017 01:08:50 +0000 (+0000) Subject: Weaken restriction in r304862 to allow implicit deduction guides to reference X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7b921168f7801271b0608064bf451893957d3cb;p=clang Weaken restriction in r304862 to allow implicit deduction guides to reference the injected-class-name of a specialization that uses a partial / explicit specialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304957 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 275039fc0a..b109ca0337 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7721,7 +7721,8 @@ public: const MultiLevelTemplateArgumentList &TemplateArgs); NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, - const MultiLevelTemplateArgumentList &TemplateArgs); + const MultiLevelTemplateArgumentList &TemplateArgs, + bool FindingInstantiatedContext = false); DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, const MultiLevelTemplateArgumentList &TemplateArgs); diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 9e8b4d55d6..148ce24293 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4807,7 +4807,7 @@ static NamedDecl *findInstantiationOf(ASTContext &Ctx, DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC, const MultiLevelTemplateArgumentList &TemplateArgs) { if (NamedDecl *D = dyn_cast(DC)) { - Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs); + Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true); return cast_or_null(ID); } else return DC; } @@ -4839,7 +4839,8 @@ DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC, /// (X::::KnownValue). \p FindInstantiatedDecl performs /// this mapping from within the instantiation of X. NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, - const MultiLevelTemplateArgumentList &TemplateArgs) { + const MultiLevelTemplateArgumentList &TemplateArgs, + bool FindingInstantiatedContext) { DeclContext *ParentDC = D->getDeclContext(); // FIXME: Parmeters of pointer to functions (y below) that are themselves // parameters (p below) can have their ParentDC set to the translation-unit @@ -5007,8 +5008,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // meaningless to attempt to find an instantiation of D within the // specialization.) // FIXME: The standard doesn't say what should happen here. - if (usesPartialOrExplicitSpecialization(Loc, - cast(SubstRecord))) { + if (FindingInstantiatedContext && + usesPartialOrExplicitSpecialization( + Loc, cast(SubstRecord))) { Diag(Loc, diag::err_specialization_not_primary_template) << T << (SubstRecord->getTemplateSpecializationKind() == TSK_ExplicitSpecialization); diff --git a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index ede2844c23..159b7072e6 100644 --- a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -271,4 +271,12 @@ namespace tuple_tests { template <> class tuple<> {}; tuple a = {1, 2, 3}; // expected-error {{no viable constructor or deduction guide}} } + + namespace libcxx_3 { + template struct scoped_lock { + scoped_lock(T...); + }; + template<> struct scoped_lock<> {}; + scoped_lock l = {}; + } }