diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 381e0de232e..db6d9421b46 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -2126,7 +2126,31 @@ public class AST2CPPTests extends AST2BaseTest { assertSame(friends[0], set); 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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 45cafeb5d90..2b5c4d22120 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -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,18 +274,24 @@ public class ClassTypeHelper { while (decl instanceof ICPPASTTemplateDeclaration) decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); - for (IASTDeclarator dtor : dtors) { - binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); - if (binding instanceof ICPPMethod) - result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); + 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(); - dtor = ASTQueries.findInnermostDeclarator(dtor); - binding = dtor.getName().resolveBinding(); - if (binding instanceof ICPPMethod) { - result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); + 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();