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:
parent
86ef3fc08c
commit
6543fd0bb7
2 changed files with 42 additions and 12 deletions
|
@ -2126,7 +2126,31 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertSame(friends[0], set);
|
assertSame(friends[0], set);
|
||||||
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 {
|
||||||
|
|
|
@ -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,18 +274,24 @@ 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;
|
||||||
for (IASTDeclarator dtor : dtors) {
|
if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) {
|
||||||
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
|
IASTDeclarator[] dtors = sdecl.getDeclarators();
|
||||||
if (binding instanceof ICPPMethod)
|
for (IASTDeclarator dtor : dtors) {
|
||||||
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
|
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||||
|
if (binding instanceof ICPPMethod)
|
||||||
|
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;
|
||||||
dtor = ASTQueries.findInnermostDeclarator(dtor);
|
if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) {
|
||||||
binding = dtor.getName().resolveBinding();
|
IASTDeclarator dtor = fdef.getDeclarator();
|
||||||
if (binding instanceof ICPPMethod) {
|
dtor = ASTQueries.findInnermostDeclarator(dtor);
|
||||||
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
|
binding = dtor.getName().resolveBinding();
|
||||||
|
if (binding instanceof ICPPMethod) {
|
||||||
|
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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue