From: Richard Smith Date: Fri, 20 Apr 2012 07:12:26 +0000 (+0000) Subject: Replace r155185 with a better fix, which also addresses PR12557. When looking X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c93e014cd43b08812370cfc8ef7bb7b92305f8fb;p=clang Replace r155185 with a better fix, which also addresses PR12557. When looking up an elaborated type specifier in a friend declaration, only look for type declarations, per [basic.lookup.elab]p2. If we know that the redeclaration lookup for a friend class template in a dependent context finds a non-template, don't delay the diagnostic to instantiation time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155187 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index a0b996beec..e16e7d67c6 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -867,7 +867,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, // Find any previous declaration with this name. DeclContext *SemanticContext; - LookupResult Previous(*this, Name, NameLoc, LookupOrdinaryName, + LookupResult Previous(*this, Name, NameLoc, LookupTagName, ForRedeclaration); if (SS.isNotEmpty() && !SS.isInvalid()) { SemanticContext = computeDeclContext(SS, true); @@ -938,7 +938,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, while (!OutermostContext->isFileContext()) OutermostContext = OutermostContext->getLookupParent(); - if (PrevClassTemplate && + if (PrevDecl && (OutermostContext->Equals(PrevDecl->getDeclContext()) || OutermostContext->Encloses(PrevDecl->getDeclContext()))) { SemanticContext = PrevDecl->getDeclContext(); @@ -951,7 +951,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, } } - if (CurContext->isDependentContext()) { + if (CurContext->isDependentContext() && PrevClassTemplate) { // If this is a dependent context, we don't want to link the friend // class template to the template in scope, because that would perform // checking of the template parameter lists that can't be performed diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index 4d69ac4f71..bd2accee3c 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -94,13 +94,3 @@ namespace rdar9676205 { }; }; } - -namespace Redecl { - struct S { - int packaged_task; - template class future { - template friend class packaged_task; - }; - future share; - }; -} diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 9c95fa0151..2b05527cf1 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -243,3 +243,27 @@ namespace rdar11147355 { A::B ab; } + +namespace RedeclUnrelated { + struct S { + int packaged_task; + template class future { + template friend class packaged_task; + }; + future share; + }; +} + +namespace PR12557 { + template + struct Foo; + + template + struct Bar { + typedef Foo_ Foo; // expected-note {{previous}} + + template friend struct Foo; // expected-error {{redefinition of 'Foo' as different kind of symbol}} + }; + + Bar b; +}