<div dir="ltr">Jeff, <br><br>Yes, Type::getAs is better than a normal cast. You get nullptr back if you try to cast to an invalid type.<br>From Type.h<br><br>05253 // Member-template getAs<specific type>'.<br>05254 template <typename T> const T *Type::getAs() const {<br>05255 ArrayType_cannot_be_used_with_getAs<T> at;<br>05256 (void)at;<br>05257 <br>05258 // If this is directly a T type, return it.<br>05259 if (const T *Ty = dyn_cast<T>(this))<br>05260 return Ty;<br>05261 <br>05262 // If the canonical form of this type isn't the right kind, reject it.<br>05263 if (!isa<T>(CanonicalType))<br>05264 return nullptr;<br>05265 <br>05266 // If this is a typedef for the type, strip the typedef off without<br>05267 // losing all typedef information.<br>05268 return cast<T>(getUnqualifiedDesugaredType());<br>05269 }</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 5, 2015 at 5:09 AM, Jeff Waller <span dir="ltr"><<a href="mailto:truthset@gmail.com" target="_blank">truthset@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><div>On Mar 4, 2015, at 6:41 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><blockquote type="cite"><div dir="ltr"><div>This is wrong:</div><div><br></div><div> if(type->isRecordType())</div><div> {</div><div> const RecordType *asRecordType = static_cast<const RecordType*>(type);<br></div><div><br></div><div>Your Type is not necessarily a RecordType here; it might be a typedef for a record type or some other type sugar node. The right way to write this is:</div><div><br></div><div> if (const RecordType *asRecordType = type->getAs<RecordType>())</div></div></blockquote><div><br></div></span><div>Hey great, and thanks, is getAs always the thing to do versus simple casting?</div><span class=""><br><blockquote type="cite"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 4, 2015 at 3:15 PM, Jeff Waller <span dir="ltr"><<a href="mailto:truthset@gmail.com" target="_blank">truthset@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><pre style="white-space:pre-wrap"><br></pre><pre style="white-space:pre-wrap">A cross-post from cfe-users. I think there will be no luck</pre><pre style="white-space:pre-wrap">on that list.</pre><pre style="white-space:pre-wrap">=======================</pre><pre style="white-space:pre-wrap">I’m getting the failure:
void clang::RecordDecl::LoadFieldsFromExternalStorage() const: Assertion `hasExternalLexicalStorage() && Source && "No external storage?"' failed.
when trying to iterate over a RecordDecl and not sure even what’s going on let along how to deal with it:
I’m proceeding from the example in
<a href="http://clang.llvm.org/docs/LibASTMatchersTutorial.html" target="_blank">http://clang.llvm.org/docs/LibASTMatchersTutorial.html</a>
Here is some context:
<a href="https://gist.github.com/waTeim/8757662c445ce3b4084f" target="_blank">https://gist.github.com/waTeim/8757662c445ce3b4084f</a>
Thanks in advance for any help</pre><div><br></div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></span></div><br></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>