CPP parser ambiguity

Robert Knight robertknight at gmail.com
Sat Apr 5 04:11:42 UTC 2008


The CPP parser has an ExpressionOrDeclarationAST node for statements
which are valid as both expressions and declarations and there is then
some logic (IdentifierVerifier) to pick which one to use in the context

Section 6.8 of the C++ standard states:

"There is an ambiguity in the grammar involving expression-statement s
and declaration s: An expression-statement with
a function-style explicit type conversion (5.2.3) as its leftmost
subexpression can be indistinguishable from a declaration
where the first declarator starts with a (. In those cases the statement
is a declaration. "

Unless I am missing something, it seems like this AST is unnecessary.
In which case the parser could be changed to treat anything which
successfully parses as a declaration as a declaration and not anything

I found this while investigating disappearing error messages from the
parser.  In Parser::parseExpressionOrDeclarationStatement() the parser
blocks all errors to prevent false errors when declarations are parsed
as exceptions or vice-versa.  Unfortunately this also leads to genuine
errors going missing.  


int foo =;

Doesn't report anything.  

More information about the KDevelop-devel mailing list