mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Fix and testcase for 196468, gcc-extension for C89: empty braces in initializer.
This commit is contained in:
parent
576c9b4495
commit
e3d42ea529
2 changed files with 24 additions and 0 deletions
|
@ -3892,4 +3892,20 @@ public class AST2Tests extends AST2BaseTest {
|
|||
parse( buffer.toString(), ParserLanguage.C);
|
||||
assertTrue(System.currentTimeMillis()-time < 1000);
|
||||
}
|
||||
|
||||
// int array[12]= {};
|
||||
public void testBug196468_emptyArrayInitializer() throws Exception {
|
||||
StringBuffer buffer = getContents(1)[0];
|
||||
final String content = buffer.toString();
|
||||
parse( content, ParserLanguage.CPP, false);
|
||||
parse( content, ParserLanguage.CPP, true);
|
||||
parse( content, ParserLanguage.C, true);
|
||||
try {
|
||||
parse( content, ParserLanguage.C, false);
|
||||
fail("C89 does not allow empty braces in array initializer");
|
||||
}
|
||||
catch (ParserException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -179,6 +179,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
consume();
|
||||
IASTInitializerList result = createInitializerList();
|
||||
((ASTNode) result).setOffset(startingOffset);
|
||||
|
||||
// bug 196468, gcc accepts empty braces.
|
||||
if (supportGCCStyleDesignators && LT(1) == (IToken.tRBRACE)) {
|
||||
int l = consume().getEndOffset();
|
||||
((ASTNode) result).setLength(l - startingOffset);
|
||||
return result;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int checkHashcode = LA(1).hashCode();
|
||||
// required at least one initializer list
|
||||
|
|
Loading…
Add table
Reference in a new issue