mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Prevent friend methods to be returned as declared method, bug 275358.
This commit is contained in:
parent
86ef3fc08c
commit
6543fd0bb7
2 changed files with 42 additions and 12 deletions
|
@ -2127,6 +2127,30 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame(friends[1], B);
|
||||
}
|
||||
|
||||
// class Other {
|
||||
// void m();
|
||||
// class A {
|
||||
// friend void set();
|
||||
// friend void Other::m();
|
||||
// };
|
||||
public void testFriend_Bug275358() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
ICPPClassType A = bh.assertNonProblem("A", 1);
|
||||
IFunction set = bh.assertNonProblem("set()", 3);
|
||||
IFunction m = bh.assertNonProblem("Other::m()", 8);
|
||||
|
||||
IBinding[] friends = A.getFriends();
|
||||
assertEquals(2, friends.length);
|
||||
assertSame(friends[0], set);
|
||||
assertSame(friends[1], m);
|
||||
|
||||
IBinding[] declaredMethods= A.getAllDeclaredMethods();
|
||||
assertEquals(0, declaredMethods.length);
|
||||
declaredMethods= A.getDeclaredMethods();
|
||||
assertEquals(0, declaredMethods.length);
|
||||
}
|
||||
|
||||
// class A { friend class B; friend class B; };
|
||||
// class B{};
|
||||
public void testBug59149() throws Exception {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -274,19 +274,25 @@ public class ClassTypeHelper {
|
|||
while (decl instanceof ICPPASTTemplateDeclaration)
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
if (decl instanceof IASTSimpleDeclaration) {
|
||||
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration)decl;
|
||||
if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) {
|
||||
IASTDeclarator[] dtors = sdecl.getDeclarators();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||
if (binding instanceof ICPPMethod)
|
||||
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
|
||||
}
|
||||
}
|
||||
} else if (decl instanceof IASTFunctionDefinition) {
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
final IASTFunctionDefinition fdef = (IASTFunctionDefinition)decl;
|
||||
if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) {
|
||||
IASTDeclarator dtor = fdef.getDeclarator();
|
||||
dtor = ASTQueries.findInnermostDeclarator(dtor);
|
||||
binding = dtor.getName().resolveBinding();
|
||||
if (binding instanceof ICPPMethod) {
|
||||
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
|
||||
}
|
||||
}
|
||||
} else if (decl instanceof ICPPASTUsingDeclaration) {
|
||||
IASTName n = ((ICPPASTUsingDeclaration)decl).getName();
|
||||
binding = n.resolveBinding();
|
||||
|
|
Loading…
Add table
Reference in a new issue