[cfe-dev] Accessing number of template parameter for a record type

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 10 09:31:38 PST 2019

On Sun, 8 Dec 2019 at 23:37, Awanish Pandey via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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.

On Mon, Dec 9, 2019 at 12:59 PM Richard Smith <richard at metafoo.co.uk> wrote:
>> On Sat, 7 Dec 2019 at 00:12, Awanish Pandey via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>> 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).
> --
> Thanking You
> Awanish Pandey
> PhD, CSE
> IIT Kanpur
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191210/c28a579b/attachment-0001.html>

More information about the cfe-dev mailing list