[cfe-commits] r85628 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/friend-template.cpp
Douglas Gregor
dgregor at apple.com
Fri Oct 30 15:42:42 PDT 2009
Author: dgregor
Date: Fri Oct 30 17:42:42 2009
New Revision: 85628
URL: http://llvm.org/viewvc/llvm-project?rev=85628&view=rev
Log:
When a friend is declared in a dependent context, don't even try to
match it up with a declaration in the outer scope.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/friend-template.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=85628&r1=85627&r2=85628&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Oct 30 17:42:42 2009
@@ -613,11 +613,19 @@
SemanticContext = PrevDecl->getDeclContext();
} else {
// Declarations in outer scopes don't matter. However, the outermost
- // context we computed is the semntic context for our new
+ // context we computed is the semantic context for our new
// declaration.
PrevDecl = 0;
SemanticContext = OutermostContext;
}
+
+ if (CurContext->isDependentContext()) {
+ // 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
+ // until the outer context is instantiated.
+ PrevDecl = 0;
+ }
} else if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S))
PrevDecl = 0;
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=85628&r1=85627&r2=85628&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Oct 30 17:42:42 2009
@@ -434,9 +434,10 @@
// Trigger creation of the type for the instantiation.
SemaRef.Context.getTypeDeclType(RecordInst);
- // We're done with friends now.
- if (Inst->getFriendObjectKind())
+ // Finish handling of friends.
+ if (Inst->getFriendObjectKind()) {
return Inst;
+ }
Owner->addDecl(Inst);
Modified: cfe/trunk/test/SemaTemplate/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend-template.cpp?rev=85628&r1=85627&r2=85628&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/friend-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend-template.cpp Fri Oct 30 17:42:42 2009
@@ -72,3 +72,22 @@
};
Foo<int> foo;
+
+template<typename T, T Value>
+struct X2a;
+
+template<typename T, int Size>
+struct X2b;
+
+template<typename T>
+class X3 {
+ template<typename U, U Value>
+ friend struct X2a;
+
+ template<typename U, T Value>
+ friend struct X2b;
+};
+
+X3<int> x3i; // okay
+
+X3<long> x3l; // FIXME: should cause an instantiation-time failure
More information about the cfe-commits
mailing list