[cfe-dev] -fspell-checking causing modifications to AST?

Kevin Funk kfunk at kde.org
Mon Jul 14 16:53:17 PDT 2014


Hey,

I'm a bit puzzled by the following behavior of clang when inspecting the AST 
for the following code snippet:

test.cpp:
char foo;
char bar = foo1;

$ clang++ -cc1 -ast-dump test.cpp:
main.cpp:2:12: error: use of undeclared identifier 'foo1'; did you mean 'foo'?
(...)
`-VarDecl 0xa19cb0 <line:2:1, col:12> col:6 bar 'char' cinit
  `-ImplicitCastExpr 0xa19d60 <col:12> 'char' <LValueToRValue>
    `-DeclRefExpr 0xa19d38 <col:12> 'char' lvalue Var 0xa19c40 'foo' 'char'

So, Clang seems to interpret 'foo1' as a typo 'foo'. This is still fine.
However, Clang also "fixes up the code" and pretends that 'foo1' *is* 'foo' 
which -ast-dump shows (see last line of the dump). This is odd.

Obviously, this is only the case if -fno-spell-checking is *not* passed to 
clang++. With -fno-spell-checking I get this instead:

$ clang++ -cc1 -ast-dump test.cpp -fno-spell-checking
(...)
`-VarDecl 0x1a79ca0 <line:2:1, col:6> col:6 bar 'char'

This looks fine to me.

So, my question: Is this intended behavior? Is this for error recovery in the 
parser?
If true, is there a way to both enable spell-checking but to *disable* it 
touching the AST?

Reminder: I'm working on integrating Clang (read: libclang) in KDevelop, hence 
I'm looking at this from an development tool perspective. Magic behavior 
inside Clang is somewhat undesirable there :)

Greets

-- 
Kevin Funk | kfunk at kde.org | http://kfunk.org



More information about the cfe-dev mailing list