UsingShadowDecl everywhere?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

UsingShadowDecl everywhere?

Craig Silverstein
I was looking at OverloadExpr::decls_begin() for an overloaded
function call.  My code was behaving oddly because I knew this decl
should be a function, but it wasn't.  It turns out it was (properly) a
UsingShadowDecl.  The decl's getTargetDecl() was the function decl I
was expecting.

But now I'm paranoid that UsingShadowDecl may come between me and the
'real' decl I desire, at any time.  For instance, could a CallExpr's
getCalleeDecl() return a UsingShadowDecl?  When else might a
UsingShadowDecl pop up unexpectedly?

I think I can safely ignore this decl, if I don't care about the fact
that the name came via a using declaration, right?  I just don't know
how my code can ignore this decl, too.  Maybe there are only a few
special cases that I havee to worry about.

craig
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: UsingShadowDecl everywhere?

John McCall
On Dec 17, 2010, at 2:07 AM, Craig Silverstein wrote:

> I was looking at OverloadExpr::decls_begin() for an overloaded
> function call.  My code was behaving oddly because I knew this decl
> should be a function, but it wasn't.  It turns out it was (properly) a
> UsingShadowDecl.  The decl's getTargetDecl() was the function decl I
> was expecting.
>
> But now I'm paranoid that UsingShadowDecl may come between me and the
> 'real' decl I desire, at any time.  For instance, could a CallExpr's
> getCalleeDecl() return a UsingShadowDecl?  When else might a
> UsingShadowDecl pop up unexpectedly?

Shadow declarations should only show up in "found" declarations,
which I think are only ever stored as part of a DeclAccessPair.
Otherwise we should already have looked through the shadow decl.

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: UsingShadowDecl everywhere?

Craig Silverstein
} Shadow declarations should only show up in "found" declarations,
} which I think are only ever stored as part of a DeclAccessPair.
} Otherwise we should already have looked through the shadow decl.

Is there a way to summarize how they might be exposed through methods
on AST classes?  Like would redecls_begin()/end() show a using shadow
decl?  I don't see DeclAccessPair as part of the API for AST nodes, so
I'm guessing this is at a layer that's hidden from end users (like
myself).

craig
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: UsingShadowDecl everywhere?

John McCall
On Dec 17, 2010, at 2:42 PM, Craig Silverstein wrote:
> } Shadow declarations should only show up in "found" declarations,
> } which I think are only ever stored as part of a DeclAccessPair.
> } Otherwise we should already have looked through the shadow decl.
>
> Is there a way to summarize how they might be exposed through methods
> on AST classes?

1)  Lookups can find shadow declarations, and they exist in the decl hierarchy.  So the lookup and iteration methods on DeclContext can find them.
2)  Anything that's specifically storing a raw lookup result might point to a shadow declaration.  Generally this will be obvious because you'll actually be working with a DeclAccessPair.
3)  Everything else will have already looked through the using declaration.

>  Like would redecls_begin()/end() show a using shadow decl?

No.

>  I don't see DeclAccessPair as part of the API for AST nodes, so
> I'm guessing this is at a layer that's hidden from end users (like
> myself).

It's part of the API.  I'm not surprised you haven't seen it before, because there are relatively few places that need to store a raw lookup result, but it's there.

IIRC, the only places which need it are:
 - MemberExpr (which needs to store the raw lookup result for a resolved lookup with a dependent base type, e.g. T().A::foo)
 - UnresolvedLookupExpr
 - UnresolvedMemberExpr

OverloadExpr::decls_iterator's operator* returns a NamedDecl* for convenience, but it's really an iterator over DeclAccessPairs.

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: UsingShadowDecl everywhere?

Craig Silverstein
Great, this is very helpful -- thanks for all the info!

craig
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev