[cfe-dev] getEndLoc of a DeclRefExpr
Nico Weber
thakis at chromium.org
Tue Oct 26 07:40:02 PDT 2010
On Mon, Oct 25, 2010 at 9:44 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Oct 24, 2010, at 6:28 PM, Nico Weber wrote:
>
>> Hi,
>>
>> DeclRefExpr::getEndLoc() always returns the same as
>> DeclRefExpr::getBeginLoc(). Is there a reason for this? It's a bit
>> annoying when using the Rewriter with DeclRefExprs.
>>
>> This happens because getEndLoc() delegates to the SourceRange of the
>> DeclRefExpr's NameInfo (see DeclRefExpr::getSourceRange() in
>> Expr.cpp).
>>
>> If this is not by design: The attached patch fixes the problem. All
>> tests still pass.
>
> This *is* by design; for example, the diagnostic printer handles these ranges correctly. The SourceRange points to the beginning of the start/end tokens, and you can use Preprocessor::getLocForEndOfToken() to get the ending location in characters.
Thanks, that makes sense in a way. Can you think of a test that would
fail with my patch? It might be worth adding one.
More information about the cfe-dev
mailing list