[cfe-commits] r141515 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/temp/temp.decls/temp.friend/p1.cpp
Douglas Gregor
dgregor at apple.com
Sun Oct 9 13:59:17 PDT 2011
Author: dgregor
Date: Sun Oct 9 15:59:17 2011
New Revision: 141515
URL: http://llvm.org/viewvc/llvm-project?rev=141515&view=rev
Log:
A friend template specialization is also dependent if any of its
template arguments are dependent. Fixes PR10913.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=141515&r1=141514&r2=141515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 9 15:59:17 2011
@@ -4987,8 +4987,12 @@
// that either the specialized function type or the specialized
// template is dependent, and therefore matching will fail. In
// this case, don't check the specialization yet.
+ bool InstantiationDependent = false;
if (isFunctionTemplateSpecialization && isFriend &&
- (NewFD->getType()->isDependentType() || DC->isDependentContext())) {
+ (NewFD->getType()->isDependentType() || DC->isDependentContext() ||
+ TemplateSpecializationType::anyDependentTemplateArguments(
+ TemplateArgs.getArgumentArray(), TemplateArgs.size(),
+ InstantiationDependent))) {
assert(HasExplicitTemplateArgs &&
"friend function specialization without template args");
if (CheckDependentFunctionTemplateSpecialization(NewFD, TemplateArgs,
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp?rev=141515&r1=141514&r2=141515&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p1.cpp Sun Oct 9 15:59:17 2011
@@ -332,3 +332,27 @@
template class B<int>; // expected-note {{in instantiation}}
}
+
+namespace PR10913 {
+ template<class T> class X;
+
+ template<class T> void f(X<T> *x) {
+ x->member = 0;
+ }
+
+ template<class U, class T> void f2(X<T> *x) {
+ x->member = 0; // expected-error{{'member' is a protected member of 'PR10913::X<int>'}}
+ }
+
+ template<class T> class X {
+ friend void f<T>(X<T> *x);
+ friend void f2<T>(X<int> *x);
+
+ protected:
+ int member; // expected-note{{declared protected here}}
+ };
+
+ template void f(X<int> *);
+ template void f2<int>(X<int> *);
+ template void f2<float>(X<int> *); // expected-note{{in instantiation of function template specialization 'PR10913::f2<float, int>' requested here}}
+}
More information about the cfe-commits
mailing list