[cfe-dev] How to use clang::ast_type_traits::DynTypedNode?
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Tue Feb 23 08:47:09 PST 2016
Oh sorry, I didn't realize you actually have DynTypedNode. DynTypedNode has
a get<T> method to retrieve a pointer to the underlying type.
On Tue, Feb 23, 2016 at 5:44 PM victor <pedretti_86 at hotmail.com> wrote:
> Hi Jonathan,
>
> Something is failing. I have this:
>
>
> ArrayRef<ast_type_traits::DynTypedNode> pv =
> Context->getParents<MemberExpr>(*member);
>
> size_t size = pv.size();
>
> if(size > 0){
>
> if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {}
> }
>
> The compiler says:
>
> /usr/lib/llvm-3.6/include/llvm/Support/Casting.h:56:24: error: cannot
> initialize a parameter of type 'const clang::Decl *' with an rvalue of
> type 'const clang::ast_type_traits::DynTypedNode *'
> return To::classof(&Val);
> ^~~~
>
>
> > Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?
> > To: pedretti_86 at hotmail.com; klimek at google.com; cfe-dev at lists.llvm.org
> > From: jonathan at codesourcery.com
> > Date: Tue, 23 Feb 2016 09:13:21 -0700
>
> >
> >
> >
> > On 2/23/16 9:07 AM, victor via cfe-dev wrote:
> > > Thanks for answering, Manuel.
> > >
> > > However, your code didn't work:
> > >
> > > clases_file.cpp:35:22: error: variable 'MD' with type 'const auto *'
> > > has incompatible initializer of type 'const clang::CXXMethodDecl'
> > > if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(pv[size-1])) {
> > >
> > > ^
> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > You need to take the address of it as dyn_cast works on pointers, not
> > references:
> >
> > if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {
> >
> >
> > Jon
> >
> > --
> > Jon Roelofs
> > jonathan at codesourcery.com
> > CodeSourcery / Mentor Embedded
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160223/b2df55de/attachment.html>
More information about the cfe-dev
mailing list