mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
fix for bug 268714, NPE in CPPVisitor.getContainingScope()
This commit is contained in:
parent
8032868167
commit
85c91a8433
3 changed files with 39 additions and 17 deletions
|
@ -7004,4 +7004,18 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
|
||||
// struct A {int a;};
|
||||
//
|
||||
// int foo();
|
||||
// int bar(A);
|
||||
//
|
||||
// int func() {
|
||||
// bar((A){foo()});
|
||||
// }
|
||||
public void testBug268714() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ package org.eclipse.cdt.core.suite;
|
|||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorOldTests;
|
||||
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
|
||||
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTests;
|
||||
import org.eclipse.cdt.core.internal.tests.PositionTrackerTests;
|
||||
import org.eclipse.cdt.core.internal.tests.ResourceLookupTests;
|
||||
|
@ -54,8 +56,8 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
|
||||
|
||||
// Add all success tests
|
||||
//suite.addTest(CDescriptorTests.suite());
|
||||
//suite.addTest(CDescriptorOldTests.suite());
|
||||
suite.addTest(CDescriptorTests.suite());
|
||||
suite.addTest(CDescriptorOldTests.suite());
|
||||
suite.addTest(ErrorParserTests.suite());
|
||||
suite.addTest(ParserTestSuite.suite());
|
||||
suite.addTest(AllCoreTests.suite());
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
|
@ -812,14 +813,16 @@ public class CPPVisitor extends ASTQueries {
|
|||
}
|
||||
} else if (node instanceof IASTInitializerExpression) {
|
||||
IASTNode parent = node.getParent();
|
||||
while (!(parent instanceof IASTDeclarator))
|
||||
while (!(parent instanceof IASTDeclarator || parent instanceof IASTTypeIdInitializerExpression))
|
||||
parent = parent.getParent();
|
||||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||
IASTName name = dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
return getContainingScope(ns[ns.length - 1]);
|
||||
}
|
||||
if(parent instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||
IASTName name = dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
return getContainingScope(ns[ns.length - 1]);
|
||||
}
|
||||
}
|
||||
} else if (node instanceof IASTExpression) {
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent instanceof IASTForStatement) {
|
||||
|
@ -840,15 +843,18 @@ public class CPPVisitor extends ASTQueries {
|
|||
}
|
||||
} else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) {
|
||||
IASTNode d = parent.getParent();
|
||||
while (!(d instanceof IASTDeclarator))
|
||||
while (!(d instanceof IASTDeclarator || d instanceof IASTTypeIdInitializerExpression)) {
|
||||
d = d.getParent();
|
||||
IASTDeclarator dtor = (IASTDeclarator) d;
|
||||
while (dtor.getNestedDeclarator() != null)
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
return getContainingScope(ns[ns.length - 1]);
|
||||
}
|
||||
if(d instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) d;
|
||||
while (dtor.getNestedDeclarator() != null)
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
return getContainingScope(ns[ns.length - 1]);
|
||||
}
|
||||
}
|
||||
} else if (parent instanceof ICPPASTTemplateId &&
|
||||
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
||||
|
|
Loading…
Add table
Reference in a new issue