Accessing number of template parameter for a record type

Dear all,

I want to access the number of parameters given to a template class during object creation in collectTemplateParams() ( in CGDebugInfo.cpp).

Ex
foo<int,> a; // I want 1

foo<int,char> b; // I want 2
assuming foo is template class and its default parameters are <char,char>

In collectTemplateParams(), I can find actual number of parameters, which is after desugaring the templateSpecialization type.

Is there any way that can give me the parameters count?

You’re looking for the number of template arguments, not the number of template parameters. You can find that by looking at TemplateSpecializationType::getNumArgs() (prior to desugaring, which will remove the difference between the types of a and b).

Hi Richard,

Thanks for the suggestion. Yes, I have already retrieved that before the desugaring. I want to access this value after the desugaring. The main issue is after the desugaring it becomes the RecordType, in this type the number of parameters is always the same.
So, I think, I have to pass this information in the RecordType even after desugaring. What will be the best way to achieve this goal?

Hi Richard,

Thanks for the suggestion. Yes, I have already retrieved that before the desugaring. I want to access this value after the desugaring. The main issue is after the desugaring it becomes the RecordType, in this type the number of parameters is always the same.
So, I think, I have to pass this information in the RecordType even after desugaring. What will be the best way to achieve this goal?

Desugaring necessarily removes this information: “a” and “b” below have the same type, so their fully-desugared (canonical) types are by definition the same. It’s hard to say more than that without digging deeply into your use case, but if you want to present information on the type as written, you generally shouldn’t be desugaring the type.