<div dir="ltr">Hi Bruno, it works, are there suggestions saying that always using Type::getAs<> rather than llvm::dyn_cast<>?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 4, 2020 at 7:32 PM Bruno Ricci <<a href="mailto:riccibrun@gmail.com">riccibrun@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 04/08/2020 12:08, Yafei Liu via cfe-dev wrote:<br>
> Hi, all.<br>
> <br>
> I want to check if a given `clang::Type` is a std::vector<xxx> and get the type of xxx.<br>
> <br>
> I tried this `if (const auto *tst = llvm::dyn_cast<clang::TemplateSpecializationType>(type)) {}` but the condition is always false, it seems that TemplateSpecializationType is not what I think it is.<br>
> <br>
> So can what I want be done?<br>
<br>
Assuming the template specialization type is not dependent (so you have a TemplateSpecializationType<br>
and not a DependentTemplateSpecializationType), use Type::getAs<TemplateSpecializationType> to<br>
look through sugar. Consider:<br>
<br>
namespace N {<br>
template <typename T> struct S {};<br>
}<br>
<br>
using type = N::S<int>;<br>
<br>
The AST for the type alias declaration is:<br>
<br>
-TypeAliasDecl 0x559082acee80 <line:5:1, col:22> col:7 type 'N::S<int>':'N::S<int>'<br>
`-ElaboratedType 0x559082acedc0 'N::S<int>' sugar <-------------------<br>
`-TemplateSpecializationType 0x559082aced70 'S<int>' sugar S<br>
|-TemplateArgument type 'int'<br>
| `-BuiltinType 0x559082a882e0 'int'<br>
`-RecordType 0x559082aced40 'N::S<int>'<br>
`-ClassTemplateSpecialization 0x559082acec40 'S'<br>
<br>
> <br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
> <br>
</blockquote></div>