mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 297550: NPE skipping trivial initializers.
This commit is contained in:
parent
5687f0ee0f
commit
7831fac919
5 changed files with 21 additions and 12 deletions
|
@ -619,7 +619,12 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
}
|
||||
|
||||
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception {
|
||||
IASTTranslationUnit tu = parse(code, lang, useGnuExtensions);
|
||||
return parseAndCheckBindings(code, lang, useGnuExtensions, false);
|
||||
}
|
||||
|
||||
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions,
|
||||
boolean skipTrivialInitializers) throws Exception {
|
||||
IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, skipTrivialInitializers);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept(col);
|
||||
assertNoProblemBindings(col);
|
||||
|
|
|
@ -7202,4 +7202,10 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parseAndCheckBindings(code, lang);
|
||||
}
|
||||
}
|
||||
|
||||
// static a[2]= {0,0};
|
||||
public void testSkipAggregateInitializer_297550() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.C, false, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,8 +90,9 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
|||
public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||
protected static class FoundAggregateInitializer extends Exception {
|
||||
public final IASTDeclarator fDeclarator;
|
||||
public IASTDeclSpecifier fDeclSpec;
|
||||
public FoundAggregateInitializer(IASTDeclarator d) {
|
||||
public final IASTDeclSpecifier fDeclSpec;
|
||||
public FoundAggregateInitializer(IASTDeclSpecifier declSpec, IASTDeclarator d) {
|
||||
fDeclSpec= declSpec;
|
||||
fDeclarator= d;
|
||||
}
|
||||
}
|
||||
|
@ -1566,9 +1567,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
try {
|
||||
// declarator for first variant
|
||||
dtor1= initDeclarator(declspec1, option);
|
||||
} catch (FoundAggregateInitializer e) {
|
||||
e.fDeclSpec= declspec1;
|
||||
throw e;
|
||||
} catch (BacktrackException e) {
|
||||
if (acceptEmpty) {
|
||||
backup(dtorMark1);
|
||||
|
|
|
@ -1281,7 +1281,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
if (lt1 == IToken.tASSIGN && LT(2) == IToken.tLBRACE)
|
||||
throw new FoundAggregateInitializer(d);
|
||||
throw new FoundAggregateInitializer(declspec, d);
|
||||
|
||||
IASTInitializer i = optionalCInitializer();
|
||||
if (i != null) {
|
||||
|
|
|
@ -2515,7 +2515,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTDeclarator dtor2= null;
|
||||
BacktrackException bt= null;
|
||||
try {
|
||||
dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, option);
|
||||
dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option);
|
||||
verifyDtor(declspec, dtor1, option);
|
||||
|
||||
int lt1= LTcatchEOF(1);
|
||||
|
@ -2555,7 +2555,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
backup(mark);
|
||||
try {
|
||||
dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, option);
|
||||
dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option);
|
||||
if (dtor1 == null) {
|
||||
return dtor2;
|
||||
}
|
||||
|
@ -2671,12 +2671,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* request a backtrack
|
||||
* @throws FoundAggregateInitializer
|
||||
*/
|
||||
protected IASTDeclarator initDeclarator(DtorStrategy strategy, DeclarationOptions option)
|
||||
private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option)
|
||||
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
|
||||
final IASTDeclarator dtor= declarator(strategy, option);
|
||||
if (option.fAllowInitializer) {
|
||||
if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE)
|
||||
throw new FoundAggregateInitializer(dtor);
|
||||
throw new FoundAggregateInitializer(declspec, dtor);
|
||||
|
||||
IASTInitializer initializer= optionalCPPInitializer(dtor, option);
|
||||
if (initializer != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue