[cfe-dev] Interesting problem trying to obtain UsingShadowDecl from DeclRefExpr

Douglas Gregor dgregor at apple.com
Mon Apr 11 17:18:48 PDT 2011


On Mar 29, 2011, at 7:37 AM, Abramo Bagnara wrote:

> namespace ns {
> int a;
> }
> 
> int main() {
>  using ns::a;
>  return a;
> }
> 
> I need to relate DeclRefExpr for 'a' to the used UsingShadowDecl, but
> DeclRefExpr::getDecl() is designed to give me the target VarDecl instead
> of the "bridge".
> 
> Is this intentional?

It probably was, since DeclRefExpr tends to refer to the declaration as resolved. That said, it doesn't seem like there is any reason to require this behavior.

> Do I have another way to get this info?

I don't think so.

> A similar problem is present trying to obtain target UsingShadowDecl
> from another UsingShadowDecl.
> 
> This is fundamental to build a dependency graph and to detect unused
> UsingDecl.


Agreed. I think it would be perfectly reasonable to store the UsingShadowDecl within the DeclRefExpr. It might make sense, however, for the normal accessor (DeclRefExpr::getDecl()) to return the underlying declaration, and add a different accessor (say, DeclRefExpr::getReferencedDecl()) to get the result as found by name lookup.

	- Doug



More information about the cfe-dev mailing list