<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Ha, deja vu - Pratyush (cc’d) was just dealing with this exact issue in another context the other day, and Oliver we were kind of dealing with this same general issue the other week re: attributes.  <div class=""><br class=""></div><div class="">You definitely *should* be able to get the full type sugar without fuss.  The obstacle to that is in  <div class=""><br class=""></div><div class=""><font face="Menlo" class="">Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, QualType ParamType, …)</font><div class=""><br class=""></div><div class="">linked to here: <a href="https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplate.cpp#L6688" class="">https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplate.cpp#L6688</a>.</div><div class=""><br class=""></div><div class="">For some reason within that function the <span style="font-family: Menlo;" class="">Converted</span> template argument is always constructed with <font face="Menlo" class="">Context.getCanonicalType(ParamType)</font>, instead of <font face="Menlo" class="">ParamType</font>, which erases the type sugar needlessly.</div><div class=""><br class=""></div><div class="">Pratyush has solved this for the C++17 branch of that function in <a href="https://reviews.llvm.org/D77598" class="">https://reviews.llvm.org/D77598</a>, but Pratyush it is probably a good idea to replace all other instances of <span style="font-family: Menlo;" class="">Context.getCanonicalType(XYZ)</span> in that function with <span style="font-family: Menlo;" class="">XYZ</span>, e.g. this line (among others):</div><div class=""><a href="https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplate.cpp#L6955" class="">https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplate.cpp#L6955</a></div><div class=""><br class=""></div><div class="">I suspect no tests will be broken with such a change, and the result will be that template arguments will always have the proper sugar available.</div><div class=""><br class=""></div><div class="">- Dave<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 13, 2020, at 12:30 AM, David Blaikie via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Once you have the FunctionDecl you've gone too far and any type sugar<br class="">is lost, I believe. (because func<vectors32_t> is the same function as<br class="">func<unsigned int[32]> or any other typedef/alias/etc of that type<br class="">parameter, etc)<br class=""><br class="">I think you'd have to be able to see the call to the function, and go<br class="">from there to find the type as written.<br class=""><br class="">On Wed, Aug 12, 2020 at 8:14 PM Oliver Zhang via cfe-dev<br class=""><<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">Hi,<br class=""><br class="">I'm using clang-tool to extract type names in template arguments. For example,<br class=""><br class=""><blockquote type="cite" class="">typedef unsigned int vectors32_t[32];<br class="">template <typename T><br class="">func(T *const vec) {<br class="">    ...<br class="">}<br class="">int main() {<br class="">    ...<br class="">    func<vector32_t>(...);<br class="">    ...<br class="">}<br class=""></blockquote><br class=""><br class="">I'd like to get the type name "vector32_t" from func's template argument. So I use clang::FunctionDecl::getTemplateSpecializationArgs() to get func's template argument list, extract the argument from the list, and then try to get the type name for the argument by using clang::TemplateArgument::getAsType().getAsString(). However, "unsigned int [32]" is returned rather than "vector32_t".<br class=""><br class="">Any thoughts on how I can extract the type alias name "vector32_t" in my above example?<br class=""><br class="">Thanks,<br class="">Oliver<br class="">_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></blockquote>_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></div></blockquote></div><br class=""></div></div></div></body></html>