[cfe-dev] [PATCH] C++ decl/expr ambiguity resolution

Argiris Kirtzidis akyrtzi at gmail.com
Fri Aug 22 20:16:21 PDT 2008


Hi,

The attached patch disambiguates between declaration or expression 
statements. It uses tentative parsing and backtracking.
For the common cases no tentative parsing is needed; for the ambiguous 
ones, this will result in multiple type checks (for tentative parsing 
and for actual parsing).
As I've mentioned in a previous post, this can be made efficient in a 
later patch by caching the type checking results of the Action module.

About the "ambiguity resoluter":
The C++ standard doesn't define in details how the ambiguity resolution 
should work, it will only guarantee that if the statement is a valid 
declaration, it will be parsed as a declaration.
But exactly which parts of the statement should we examine to determine 
the validity of a declaration.. this is left undefined.
In practice this means that for a statement that GCC finds as invalid 
declaration, Clang may parse it as valid expression.
Such differences are not important because they are about errors, the 
more important "correct GCC code should be parsed correctly by 
Clang"-assertion is not 'compromised'.
-If GCC parses a statement without errors, Clang will parse it the same way.
-If GCC parses a statement and emits errors because it treats it as 
erroneous declaration, Clang may treat it as a correct expression instead.

Here's an example:

FuncType(a)(x,y)->z = 0;

GCC will disambiguate it as a declaration and emit errors, Clang will 
disambiguate it as an expression instead.


-Argiris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tentative-parse.patch
Type: text/x-diff
Size: 25534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080822/4cdd1830/attachment.patch>


More information about the cfe-dev mailing list