[cfe-dev] SourceLocation of CXXConstructExpr nodes

Nicola Gigante nicola.gigante at gmail.com
Tue Feb 7 05:50:05 PST 2012


Il giorno 06/feb/2012, alle ore 19:59, John McCall ha scritto:

> On Feb 4, 2012, at 2:36 PM, Nicola Gigante wrote:
>> 
>> Do you agree with me?
> 
> I agree.
> 

Ok!
And then there's another similar issue, that cause the fail
of Index/get-cursor.cpp

Consider this code:
int func() {
  double value;
  return (int)value;
}

Currently, this is the AST of the return statement (without any patch from me):
(ReturnStmt <line:3:3, col:15>
    (CStyleCastExpr <col:10, col:15> 'int' <NoOp>
      (ImplicitCastExpr <col:15> 'int' <FloatingToIntegral>
        (ImplicitCastExpr <col:15> 'double' <LValueToRValue>
          (DeclRefExpr <col:15> 'double' lvalue Var 'value' 'double'))))))

Why does the source range of the C-style cast (and consequently the
return statement) end at the beginning of the casted expression (column 15)?
IMHO, it should end at column 19, where the "value" token ends.
If so, tests like get-cursor.cpp must be updated and they would currently fail.


This creates a problem with my patch, with a piece of code like this:
struct Foo {
  Foo(int);
};

Foo func() {
  int value;
  return (Foo)value;
}

Currently the AST for the return statement is:
(ReturnStmt <line:7:3, col:15>
    (CXXConstructExpr <col:10, col:15> 'struct Foo''void (const struct Foo &) throw()' elidable
      (MaterializeTemporaryExpr <col:10, col:15> 'const struct Foo' lvalue
        (ImplicitCastExpr <col:10, col:15> 'const struct Foo' <NoOp>
          (CStyleCastExpr <col:10, col:15> 'struct Foo' <ConstructorConversion>
            (CXXConstructExpr <col:10, col:15> 'struct Foo''void (int)'
              (ImplicitCastExpr <col:15> 'int' <LValueToRValue>
                (DeclRefExpr <col:15> 'int' lvalue Var 'value' 'int')))))))))

With my patch, it is:
(ReturnStmt <line:7:3, col:14>
    (CXXConstructExpr <col:10, col:14> 'struct Foo''void (const struct Foo &) throw()' elidable
      (MaterializeTemporaryExpr <col:10, col:14> 'const struct Foo' lvalue
        (ImplicitCastExpr <col:10, col:14> 'const struct Foo' <NoOp>
          (CStyleCastExpr <col:10, col:14> 'struct Foo' <ConstructorConversion>
            (CXXConstructExpr <col:10, col:14> 'struct Foo''void (int)'
              (ImplicitCastExpr <col:15> 'int' <LValueToRValue>
                (DeclRefExpr <col:15> 'int' lvalue Var 'value' 'int')))))))))

For some reason, my patch makes the CXXConstructExpr end one character before. The point,
however, is the same as before. The return statement and all the expression nodes should end
at the _end_ of the DeclRefExpr, in this case column 19, rather than the begin.
This one-character difference however make the (already wrong) get-cursor.cpp test fail with my patch.

At this point, since this issue goes beyond the scope of my patch,
if you agree with me that both behaviors are incorrect anyway, I'd update the test to make it pass anyway or
write it right and mark it as an expected failure, and file a bug for this issue.
In the meantime, it means my patch by itself is correct (in the sense that it doesn't introduce _new_ bugs)
and I can commit it.

Is it ok?

Nicola



More information about the cfe-dev mailing list