[cfe-dev] getEndLoc of a DeclRefExpr

Douglas Gregor dgregor at apple.com
Mon Oct 25 09:44:48 PDT 2010


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.

	- Doug



More information about the cfe-dev mailing list