<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 16, 2015 at 11:51 PM, Stephan Bergmann <span dir="ltr"><<a href="mailto:sbergman@redhat.com" target="_blank">sbergman@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I naively assumed AST::Type::getAs<T>() would work regardless whether T represents sugar or not, and looking closer it is indeed specialized for TypedefType, TemplateSpecializationType, and AttributeType to make those work, but not for other sugar like SubstTemplateTypeParmType.<br>
<br>
For example, t->getAs<SubstTemplateTypeParmType>() does not work if t is a wrapping TypedefType (but happens to work if t itself already is a SubsTemplateTypeParmType).  Is that intended?<br></blockquote><div><br></div><div>I don't think it was intended. I also thought I understood how type sugar and getAs work, and this is a surprise to me as well. :)</div><div><br></div><div>I would've expected getAs to work like this:</div><div><br></div><div><div>template <typename T> const T *Type::getAs() const {</div><div>  // If this is directly a T type, return it.<br></div><div>  if (const T *Ty = dyn_cast<T>(this))</div><div>    return Ty;</div><div><div>  // If the canonical type is directly a T type, return it.</div><div>  if (const T *Ty = dyn_cast<T>(CanonicalType))</div><div>    return Ty;</div></div><div>  // Do repeated single step desugarings until we find the type or return null.</div><div>  ...</div><div>}<br></div></div><div><br></div></div></div></div>