1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Prevent friend methods to be returned as declared method, bug 275358.

This commit is contained in:
Markus Schorn 2009-05-13 12:23:35 +00:00
parent 86ef3fc08c
commit 6543fd0bb7
2 changed files with 42 additions and 12 deletions

View file

@ -2127,6 +2127,30 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(friends[1], B); 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 A { friend class B; friend class B; };
// class B{}; // class B{};
public void testBug59149() throws Exception { public void testBug59149() throws Exception {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -274,19 +274,25 @@ public class ClassTypeHelper {
while (decl instanceof ICPPASTTemplateDeclaration) while (decl instanceof ICPPASTTemplateDeclaration)
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) { 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) { for (IASTDeclarator dtor : dtors) {
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPMethod) if (binding instanceof ICPPMethod)
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
} }
}
} else if (decl instanceof IASTFunctionDefinition) { } 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); dtor = ASTQueries.findInnermostDeclarator(dtor);
binding = dtor.getName().resolveBinding(); binding = dtor.getName().resolveBinding();
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
} }
}
} else if (decl instanceof ICPPASTUsingDeclaration) { } else if (decl instanceof ICPPASTUsingDeclaration) {
IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); IASTName n = ((ICPPASTUsingDeclaration)decl).getName();
binding = n.resolveBinding(); binding = n.resolveBinding();