mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 01:35:39 +02:00
Bug 408181 - Invalid owner returned for a friend template function
This commit is contained in:
parent
e56469e20d
commit
149937682f
5 changed files with 39 additions and 7 deletions
|
@ -9321,10 +9321,10 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
// }
|
// }
|
||||||
public void testOwner() throws Exception {
|
public void testOwner() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper();
|
BindingAssertionHelper bh = getAssertionHelper();
|
||||||
ICPPBinding ns = bh.assertNonProblemOnFirstIdentifier("ns");
|
ICPPNamespace ns = bh.assertNonProblemOnFirstIdentifier("ns");
|
||||||
ICPPBinding A = bh.assertNonProblemOnFirstIdentifier("A");
|
ICPPClassType A = bh.assertNonProblemOnFirstIdentifier("A");
|
||||||
assertEquals(ns, A.getOwner());
|
assertEquals(ns, A.getOwner());
|
||||||
IBinding m = bh.assertNonProblemOnFirstIdentifier("m()");
|
ICPPMethod m = bh.assertNonProblemOnFirstIdentifier("m()");
|
||||||
assertEquals(A, m.getOwner());
|
assertEquals(A, m.getOwner());
|
||||||
assertEquals(A, bh.assertNonProblemOnFirstIdentifier("x;").getOwner());
|
assertEquals(A, bh.assertNonProblemOnFirstIdentifier("x;").getOwner());
|
||||||
assertEquals(A, bh.assertNonProblemOnFirstIdentifier("y;").getOwner());
|
assertEquals(A, bh.assertNonProblemOnFirstIdentifier("y;").getOwner());
|
||||||
|
|
|
@ -4136,6 +4136,26 @@ public class AST2TemplateTests extends AST2TestBase {
|
||||||
parseAndCheckBindings(getAboveComment());
|
parseAndCheckBindings(getAboveComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct A {
|
||||||
|
// template<typename U>
|
||||||
|
// friend void f(const A<U>& p) {}
|
||||||
|
// template<typename U>
|
||||||
|
// void m(const A<U>& p) const;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void test(const A<int>& a) {
|
||||||
|
// f(a);
|
||||||
|
// a.m(a);
|
||||||
|
// }
|
||||||
|
public void testOwnerOfFriendTemplateFunction_408181() throws Exception {
|
||||||
|
BindingAssertionHelper bh = getAssertionHelper();
|
||||||
|
ICPPFunction f = bh.assertNonProblemOnFirstIdentifier("f(a)");
|
||||||
|
assertNull(f.getOwner());
|
||||||
|
ICPPClassType A = bh.assertNonProblem("A<int>");
|
||||||
|
assertEquals(A, bh.assertNonProblemOnFirstIdentifier("m(a);").getOwner());
|
||||||
|
}
|
||||||
|
|
||||||
// template <typename T> void f(T t) {
|
// template <typename T> void f(T t) {
|
||||||
// g(t);
|
// g(t);
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -1369,7 +1369,19 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
|
|
||||||
final IType type = t2.getType();
|
final IType type = t2.getType();
|
||||||
assertTrue(type instanceof IBasicType);
|
assertTrue(type instanceof IBasicType);
|
||||||
assertEquals(((IBasicType)type).getType(), IBasicType.t_int);
|
assertEquals(((IBasicType) type).getType(), IBasicType.t_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
// struct A {
|
||||||
|
// template<typename T>
|
||||||
|
// struct S;
|
||||||
|
// };
|
||||||
|
// template<typename T>
|
||||||
|
// struct A::S {};
|
||||||
|
|
||||||
|
// A::S<int> a;
|
||||||
|
public void testXXX() throws Exception {
|
||||||
|
checkBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// template <int x>
|
// template <int x>
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
||||||
|
@ -31,7 +30,7 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
|
||||||
implements ICPPFunctionTemplate, ICPPInternalTemplate {
|
implements ICPPFunctionTemplate, ICPPInternalTemplate {
|
||||||
private ObjectMap instances;
|
private ObjectMap instances;
|
||||||
|
|
||||||
public CPPFunctionTemplateSpecialization(ICPPFunction original, ICPPClassType owner,
|
public CPPFunctionTemplateSpecialization(ICPPFunction original, IBinding owner,
|
||||||
ICPPTemplateParameterMap argumentMap, ICPPFunctionType type, IType[] exceptionSpecs) {
|
ICPPTemplateParameterMap argumentMap, ICPPFunctionType type, IType[] exceptionSpecs) {
|
||||||
super(original, owner, argumentMap, type, exceptionSpecs);
|
super(original, owner, argumentMap, type, exceptionSpecs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -839,7 +839,8 @@ public class CPPTemplates {
|
||||||
} else if (decl instanceof ICPPMethod) {
|
} else if (decl instanceof ICPPMethod) {
|
||||||
spec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, owner, tpMap, type, exceptionSpecs);
|
spec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, owner, tpMap, type, exceptionSpecs);
|
||||||
} else {
|
} else {
|
||||||
spec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, owner, tpMap, type, exceptionSpecs);
|
IBinding oldOwner = decl.getOwner();
|
||||||
|
spec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, oldOwner, tpMap, type, exceptionSpecs);
|
||||||
}
|
}
|
||||||
} else if (decl instanceof ICPPConstructor) {
|
} else if (decl instanceof ICPPConstructor) {
|
||||||
spec = new CPPConstructorSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs);
|
spec = new CPPConstructorSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs);
|
||||||
|
|
Loading…
Add table
Reference in a new issue