ReturnStmt::getRetValue() location: bug or feature?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ReturnStmt::getRetValue() location: bug or feature?

Alex Denisov via cfe-dev
Hi all,
I want to find location of return expression, i.e. location between end of return keyword and semicolon. Initially I thought that SourceRange of ReturnStmt::getRetValue() is exactly what I need. But it is not, here are results for this small code sample ( I put text that corresponds to getRetValue()->getSourceRange() in comments):

struct foo { foo (int x){} };

foo fun0 () { return foo(0); } //  foo(0)
foo fun1 () { foo f1(1); return f1; //  f1
foo fun2 () { return {2}; } // {2}
foo fun3 () { return 3; } // return 3

So in the last case getRetValue()  source range is "return 3".  To me this looks more like a bug, than a feature. 

From AST point of view fun0 and fun 3 are pretty similar:

return from fun0:

ExprWithCleanups 0x4593138 'struct foo'
`-CXXConstructExpr 0x4593100 'struct foo' 'void (struct foo &&) noexcept' elidable
  `-MaterializeTemporaryExpr 0x4593098 'struct foo' xvalue
    `-CXXFunctionalCastExpr 0x4593070 'struct foo' functional cast to struct foo <ConstructorConversion>
      `-CXXConstructExpr 0x4592ee8 'struct foo' 'void (int)'
        `-IntegerLiteral 0x4592b48 'int' 0


return from fun3:

ExprWithCleanups 0x37393f8 'struct foo'
`-CXXConstructExpr 0x37393c0 'struct foo' 'void (struct foo &&) noexcept' elidable
  `-MaterializeTemporaryExpr 0x37393a8 'struct foo' xvalue
    `-ImplicitCastExpr 0x3739390 'struct foo' <ConstructorConversion>
      `-CXXConstructExpr 0x3739358 'struct foo' 'void (int)'
        `-IntegerLiteral 0x3739338 'int' 3

-Roman

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev