1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Owner of forward class declarations, bug 290693.

This commit is contained in:
Markus Schorn 2009-09-28 13:24:16 +00:00
parent d1d38f73dc
commit cb647d08f0
2 changed files with 38 additions and 4 deletions

View file

@ -7411,4 +7411,26 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(declNames.length, i);
assertEquals(defNames.length, j);
}
// class X {
// struct S* m1;
// struct T;
// struct T* m2;
// };
public void testStructOwner_290693() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPClassType S= bh.assertNonProblem("S*", 1);
assertNull(S.getOwner());
ICPPClassType X= bh.assertNonProblem("X {", 1);
ICPPClassType T= bh.assertNonProblem("T;", 1);
assertSame(X, T.getOwner());
T= bh.assertNonProblem("T* m2", 1);
assertSame(X, T.getOwner());
}
}

View file

@ -2023,18 +2023,30 @@ public class CPPVisitor extends ASTQueries {
*/
public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) {
// Search for declaration
boolean isFriend= false;
boolean isNonSimpleElabDecl= false;
while (!(node instanceof IASTDeclaration)) {
if (node == null)
return null;
if (node instanceof IASTElaboratedTypeSpecifier) {
isNonSimpleElabDecl= true;
final IASTNode parent= node.getParent();
if (parent instanceof IASTSimpleDeclaration) {
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent;
if (sdecl.getDeclarators().length==0) {
isNonSimpleElabDecl= false;
}
}
}
node= node.getParent();
}
boolean isFriend= false;
if (node instanceof IASTSimpleDeclaration) {
ICPPASTDeclSpecifier declSpec= (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) node;
ICPPASTDeclSpecifier declSpec= (ICPPASTDeclSpecifier) sdecl.getDeclSpecifier();
if (declSpec.isFriend()) {
isFriend= true;
}
}
} else if (node instanceof IASTFunctionDefinition) {
IASTFunctionDefinition funcDefinition = (IASTFunctionDefinition) node;
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) funcDefinition.getDeclSpecifier();
@ -2058,7 +2070,7 @@ public class CPPVisitor extends ASTQueries {
break;
}
if (node instanceof IASTCompositeTypeSpecifier) {
if (isFriend)
if (isFriend || isNonSimpleElabDecl)
continue;
name= ((IASTCompositeTypeSpecifier) node).getName();
break;