1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Bug 513681 - Unresolved name with a friend declaration in a namespace

Change-Id: I778886f802576a9b8d7804eb32abfe091bf0568d
This commit is contained in:
Sergey Prigogin 2017-03-14 20:25:23 -07:00
parent 8da53f1e5e
commit c5dc285ca5
3 changed files with 63 additions and 3 deletions

View file

@ -10160,4 +10160,24 @@ public class AST2TemplateTests extends AST2TestBase {
public void testNoexceptSpecifierInTypeTemplateArgument_511186() throws Exception { public void testNoexceptSpecifierInTypeTemplateArgument_511186() throws Exception {
parseAndCheckBindings(); parseAndCheckBindings();
} }
// namespace ns {
//
// template <typename T>
// class A {
// friend void waldo(A<int> flag);
// };
//
// void waldo(A<int> flag);
//
// }
//
// ns::A<int> a;
//
// void func() {
// waldo(a);
// }
public void testFriendFunctionDeclarationInNamespace_513681() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -268,4 +268,37 @@ public class IndexMultiFileTest extends IndexBindingResolutionTestBase {
// This code is invalid, so we don't checkBindings(). // This code is invalid, so we don't checkBindings().
// If the test gets this far (doesn't throw in setup() during indexing), it passes. // If the test gets this far (doesn't throw in setup() during indexing), it passes.
} }
// test.h
// namespace ns {
//
// template <typename T>
// class A {
// friend void waldo(A<int> p);
// };
//
// void waldo(A<int> p);
//
// }
// test.cpp *
// #include "test.h"
//
// ns::A<int> b;
//
// void test() {
// ns::waldo(b);
// }
// z.cpp
// #include "test.h"
//
// ns::A<int> a;
//
// void func() {
// waldo(a);
// }
public void testFriendFunctionDeclarationInNamespace_513681() throws Exception {
checkBindings();
}
} }

View file

@ -1105,14 +1105,21 @@ public class CPPTemplates {
} else if (decl instanceof ICPPMethod && classOwner != null) { } else if (decl instanceof ICPPMethod && classOwner != null) {
functionSpec = new CPPMethodSpecialization((ICPPMethod) decl, classOwner, tpMap, type, exceptionSpecs); functionSpec = new CPPMethodSpecialization((ICPPMethod) decl, classOwner, tpMap, type, exceptionSpecs);
} else if (decl instanceof ICPPFunction) { } else if (decl instanceof ICPPFunction) {
IBinding oldOwner = decl.getOwner(); if (type.isSameType(func.getType())) {
functionSpec = new CPPFunctionSpecialization((ICPPFunction) decl, oldOwner, tpMap, type, exceptionSpecs); // There is no need to create a CPPFunctionSpecialization object since the function is
// a friend function with the type that is not affected by the specialization.
// See http://bugs.eclipse.org/513681
spec = func;
} else {
IBinding oldOwner = decl.getOwner();
functionSpec = new CPPFunctionSpecialization(func, oldOwner, tpMap, type, exceptionSpecs);
}
} }
if (functionSpec != null) { if (functionSpec != null) {
functionSpec.setParameters(specializeParameters(func.getParameters(), functionSpec, context, functionSpec.setParameters(specializeParameters(func.getParameters(), functionSpec, context,
IntegralValue.MAX_RECURSION_DEPTH)); IntegralValue.MAX_RECURSION_DEPTH));
spec = functionSpec;
} }
spec = functionSpec;
} else if (decl instanceof ITypedef) { } else if (decl instanceof ITypedef) {
InstantiationContext context = createInstantiationContext(tpMap, owner, point); InstantiationContext context = createInstantiationContext(tpMap, owner, point);
IType type= instantiateType(((ITypedef) decl).getType(), context); IType type= instantiateType(((ITypedef) decl).getType(), context);