mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Bug 484824 - Disallow initializers in type-ids in C code
This was already disalowed in C++ code previously. Change-Id: I17f0b19253394896a980e2bbeb610bbbf266d012 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
f69b77089b
commit
fe5aea4644
2 changed files with 13 additions and 1 deletions
|
@ -7569,4 +7569,16 @@ public class AST2Tests extends AST2TestBase {
|
||||||
public void testAlignas_451082() throws Exception {
|
public void testAlignas_451082() throws Exception {
|
||||||
parseAndCheckBindings(getAboveComment(), C);
|
parseAndCheckBindings(getAboveComment(), C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void foo(int waldo) {
|
||||||
|
// (waldo = 5) && waldo;
|
||||||
|
// }
|
||||||
|
public void testTypeIdWithEqualsInitializer_484824() throws Exception {
|
||||||
|
// Test that 'waldo = 5' is not parsed as a type-id, causing
|
||||||
|
// the entire expression to be parsed as a cast-expression.
|
||||||
|
// See also bug 471174, which is about the broader problem of
|
||||||
|
// binary && expressions with a parenthesized left operand
|
||||||
|
// being incorrectly parsed as cast-expressions.
|
||||||
|
parseAndCheckBindings(getAboveComment(), C);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) throws EndOfFileException, BacktrackException {
|
protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions options) throws EndOfFileException, BacktrackException {
|
||||||
if (LTcatchEOF(1) == IToken.tASSIGN) {
|
if (options.fAllowInitializer && LTcatchEOF(1) == IToken.tASSIGN) {
|
||||||
final int offset= consume().getOffset();
|
final int offset= consume().getOffset();
|
||||||
IASTInitializerClause initClause = initClause();
|
IASTInitializerClause initClause = initClause();
|
||||||
IASTEqualsInitializer result= getNodeFactory().newEqualsInitializer(initClause);
|
IASTEqualsInitializer result= getNodeFactory().newEqualsInitializer(initClause);
|
||||||
|
|
Loading…
Add table
Reference in a new issue