<div dir="ltr">Oh sorry, I didn't realize you actually have DynTypedNode. DynTypedNode has a get<T> method to retrieve a pointer to the underlying type.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 23, 2016 at 5:44 PM victor <<a href="mailto:pedretti_86@hotmail.com">pedretti_86@hotmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">Hi Jonathan,<br><br>Something is failing. I have this:</div></div><div><div dir="ltr"><br><br>ArrayRef<ast_type_traits::DynTypedNode> pv = Context->getParents<MemberExpr>(*member);<br><br></div></div><div><div dir="ltr">size_t size = pv.size();<br> <br>if(size > 0){</div></div><div><div dir="ltr"><br> if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {}<br>}<br><br></div></div><div><div dir="ltr">The compiler says:<br><br>/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<br> type 'const clang::ast_type_traits::DynTypedNode *'<br> return To::classof(&Val);<br> ^~~~<br><br><br><div></div></div></div><div><div dir="ltr"><div>> Subject: Re: [cfe-dev] How to use clang::ast_type_traits::DynTypedNode?<br></div></div></div><div><div dir="ltr"><div>> To: <a href="mailto:pedretti_86@hotmail.com" target="_blank">pedretti_86@hotmail.com</a>; <a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>; <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>> From: <a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>> Date: Tue, 23 Feb 2016 09:13:21 -0700</div></div></div><div><div dir="ltr"><div><br>> <br>> <br>> <br>> On 2/23/16 9:07 AM, victor via cfe-dev wrote:<br>> > Thanks for answering, Manuel.<br>> ><br>> > However, your code didn't work:<br>> ><br>> > clases_file.cpp:35:22: error: variable 'MD' with type 'const auto *'<br>> > has incompatible initializer of type 'const clang::CXXMethodDecl'<br>> > if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(pv[size-1])) {<br>> ><br>> > ^<br>> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>> <br>> You need to take the address of it as dyn_cast works on pointers, not <br>> references:<br>> <br>> if (const auto* MD = llvm::dyn_cast<CXXMethodDecl>(&pv[size-1])) {<br>> <br>> <br>> Jon<br>> <br>> -- <br>> Jon Roelofs<br>> <a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>> CodeSourcery / Mentor Embedded<br></div></div></div></blockquote></div>