[cfe-dev] getEndLoc of a DeclRefExpr

Douglas Gregor dgregor at apple.com
Wed Oct 27 09:04:23 PDT 2010


On Oct 26, 2010, at 5:27 AM, Jan Bierbaum wrote:

> Douglas Gregor meinte am 25.10.2010 18:44:
>>> 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).
>> 
>> 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.
> 
> Since this is at least the third time in a few months that somebody
> (including myself) got confused about the way SourceRange works, how
> about adding a small section about this to the "Clang Internals" on the
> web site?
> 
> Attached is my take on this, based on your earlier post [1] to this list.

Thanks! Committed as r117450.

  - Doug



More information about the cfe-dev mailing list