1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 525645 - Named type specifiers in friend declarations

Change-Id: Ia67fb35ef3d20cde97322c07e697e3437c6c769d
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
Thomas Corbat 2017-10-05 21:35:37 +02:00
parent a7be934ba2
commit 07e8917eb5
2 changed files with 23 additions and 2 deletions

View file

@ -2403,6 +2403,22 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertSame(friends[1], B);
}
// class B;
// class A {
// friend B;
// };
// class B{};
public void testForwardDeclaredFriend_525645() throws Exception {
final String code = getAboveComment();
BindingAssertionHelper bh = new AST2AssertionHelper(code, true);
ICPPClassType A = bh.assertNonProblem("A", 1);
ICPPClassType B = bh.assertNonProblem("B", 1);
IBinding[] friends = A.getFriends();
assertEquals(1, friends.length);
assertSame(friends[0], B);
}
// class Other {
// void m(); };
// class A {

View file

@ -53,6 +53,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
@ -115,8 +116,12 @@ public class ClassTypeHelper {
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier();
if (declSpec.isFriend()) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) {
if (dtors.length == 0) {
if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) {
resultSet.put(((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding());
} else if (declSpec instanceof ICPPASTNamedTypeSpecifier) {
resultSet.put(((ICPPASTNamedTypeSpecifier) declSpec).getName().resolveBinding());
}
} else {
for (IASTDeclarator dtor : dtors) {
if (dtor == null) break;