[PATCH] Fix missing source location in CXXTemporaryObjectExpr.

Eli Friedman eli.friedman at gmail.com
Wed Sep 4 14:05:54 PDT 2013


On Wed, Sep 4, 2013 at 4:24 AM, Enea Zaffanella <zaffanella at cs.unipr.it>wrote:

> When dumping the following C++11 chunk of code
>
> $ cat chunk.cc
> struct A { A(int, int); };
> A a_paren( A(0,0) );
> A a_range( A{0,0} );
>
> the CXXTemporaryObjectExpr generated by A{0,0}
> is missing a proper end location
> (the source location is correctly set for A(0,0)).
>
> $ clang -cc1 -std=c++11 -ast-dump chunk.cc
> [...]
> `-VarDecl 0x5a963e0 <line:3:1, col:19> a_range 'struct A'
>   `-CXXConstructExpr 0x5a96570 <col:3, col:19> 'struct A' 'void (struct A
> &&) noexcept' elidable
>     `-MaterializeTemporaryExpr 0x5a96550 <col:12, <invalid sloc>> 'struct
> A' xvalue
>       `-CXXTemporaryObjectExpr 0x5a964d8 <col:12, <invalid sloc>> 'struct
> A' 'void (int, int)'
>         |-IntegerLiteral 0x5a96448 <col:14> 'int' 0
>         `-IntegerLiteral 0x5a96468 <col:16> 'int' 0
>
>
> Please find attached a patch (with testcase) fixing this issue.
> OK to commit?
>
>
+    if (Kind.getKind() == InitializationKind::IK_DirectList)
+      ParenRange = SourceRange(LBraceLoc, RBraceLoc);
+    else
       ParenRange = Kind.getParenRange();

This isn't right: there aren't any parentheses.  getParenRange() on a
CXXTemporaryObjectExpr shouldn't return source locations pointing at tokens
which aren't parentheses.

You should be able to fix this purely in
CXXTemporaryObjectExpr::getLocStart()/getLocEnd().

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130904/9bea5a56/attachment.html>


More information about the cfe-commits mailing list