[cfe-dev] DeclContext::lookup() on a FunctionDecl

Richard Smith richard at metafoo.co.uk
Thu Aug 9 15:36:02 PDT 2012


On Thu, Aug 9, 2012 at 3:29 PM, Sean Callanan <scallanan at apple.com> wrote:

> I want to find a declaration of a struct that's declared in the body of a
> FunctionDecl.  The code looks like this:
>
> DeclarationName
> struct_name(&m_ast_context->Idents.get(m_struct_name.c_str()));
> FunctionDecl::lookup_result struct_lookup = F->lookup(struct_name);
>
> When I call lookup() here, LookupPtr.getPointer() for the FunctionDecl is
> NULL and LookupPtr.getInt() is also NULL, so lookup() returns
> lookup_result(lookup_iterator(0), lookup_iterator(0)) without regard to
> what name I pass in.
>
> Is there something wrong with this FunctionDecl, or is this expected
> behavior for FunctionDecls?
>

This is expected behavior. Lookup into FunctionDecls is not especially
meaningful, since there can be nested scopes within the function which are
not modeled by the lookup. For performance, we do not generally build the
lookup data structures for function declarations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120809/543e233a/attachment.html>


More information about the cfe-dev mailing list