Getting SubstTemplateTypeParmType Template Info

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting SubstTemplateTypeParmType Template Info

Nathan Ridge via cfe-dev
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?

Thanks,
Justin

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting SubstTemplateTypeParmType Template Info

Nathan Ridge via cfe-dev

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 a
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 arguments;
similarly, the template name there might be a template alias, and the true
type may not be a class type at all.

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

John.


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev