[cfe-dev] Getting SubstTemplateTypeParmType Template Info

John McCall via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 11 21:30:06 PDT 2019

On 4 Jul 2019, at 18:11, fdart via cfe-dev wrote:
> Hi,
> Given the below input to clang tooling, when I traverse ParameterMap's
> type, I get that std::map is a template specialization, with two 
> nested
> template specializations, std::basic_string.  Therefore I can extract 
> the
> information I'm looking for.
> #include <map>
> using String = std::string;
> using ParameterMap = std::map<String, String>;
> If we take the indirection one step further with this input to clang 
> tooling
> #include <map>
> template <typename K, typename V> using Map = std::map<K, V>;
> using String = std::string;
> using ParameterMap = Map<String, String>;
> ParameterMap someFunc() { return ParameterMap(); }
> then String is now a SubstTemplateTypeParmType.  If I desugar that, I 
> get
> that String is a record rather than a template specialization, so I 
> cannot
> get the template types of String.  Is that intended?  How can I get 
> the
> template information for String in this case?

`TemplateSpecializationType` is a sugar type representing the fact that 
type was written in source as `SomeTemplate<TemplateArgs...>`.  The
template arguments there should be the source template arguments, which
may differ from the true template arguments due to e.g. default 
similarly, the template name there might be a template alias, and the 
type may not be a class type at all.

If you don't particularly care about the spelling in source code and 
want to check if a type ultimately names a class template 
you should `getAs<RecordType>()` and then `dyn_cast` the `RecordDecl` to

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190712/36875345/attachment.html>

More information about the cfe-dev mailing list