[cfe-dev] Determining if a UsingDecl/UsingShadowDecl was used in the instantiation of a variable.

Eric Bayer via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 22 14:02:34 PDT 2019


Hi,

I have a plugin I'm working on a clang plugin where we need to determine 
all the things used in the creation of a piece of code. Right now we 
have a situation as follows:

namespace X { class Y { enum Z { A=0, B, C }; }; };
using X::Y;

void MyFunc() {
	Y::Z q;
         ...
}

What we currently do is traverse the whole of MyFunc looking for 
referenced elements using VisitStmt().  The problem I have is that I 
can't find any way to determine that "using X::Y;" was used and that it 
was involved in resolving "Y::Z" to "X::Y::Z" in the creation of "q".   
This has not been a problem for all sorts of sugar (like typedefs, type 
aliases, etc), but I am beside myself to find a way in this case.  Is 
there any way to do this?  I'm even interested if it's a sort of "long 
way around" solution. It's surprising to me that this has been this 
hard... there have been breadcrumbs for every other piece of syntactic 
sugar.

Thanks in advance,

     -Eric

PS - I thought I had found some clues, but they only seemed to work for 
functions in one case (DeclRefExpr), and templates in another 
(getInstantiatedFromUsingDecl()).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191022/c98efd4f/attachment.html>


More information about the cfe-dev mailing list