[cfe-dev] Template Qualifier Removal Question

Andrew Gozillon via cfe-dev cfe-dev at lists.llvm.org
Sat Aug 18 14:00:30 PDT 2018


Hi John,


Thank you very much, that was exactly what I was looking for!


Best Regards,

Andrew

________________________________
From: rjmccall at apple.com <rjmccall at apple.com> on behalf of John McCall <rjmccall at apple.com>
Sent: 15 August 2018 09:27:39
To: Andrew Gozillon
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Template Qualifier Removal Question

> On Aug 13, 2018, at 2:36 AM, Andrew Gozillon via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> I have a question relating to template metafunctions like remove_const that split a type from its qualifiers.
>
> I was wondering where in Clang the decision to remove const (or another qualifier or pointer) from a type is made when using templates and then where it's performed (the new type generated)? I originally thought the conversion might be in TreeTransform.h in a function like TransformQualifiedType but it doesn't appear to be the case (I could be missing something however).
>
> Sorry if the question is not entirely clear and thank you very much for your time and help!

The C++ specification gives rules for deducing template arguments from an "argument" type and a "parameter" type, where the argument type is (typically) a concrete type and the parameter type is specified in terms of some number of template parameters.  You can find these rules in the section labeled [temp.deduct], but the basic idea is that you look for types that, if substituted for the template parameters, give exactly the argument type.  So, e.g., if you have a parameter type `const T` and an argument type `const int`, the substitution `T = int` is the best match; but if the parameter type were `U`, the best substitution would be `U = const int`.

In clang, this rule is implemented in SemaTemplateDeduction.cpp.  For the specific part about qualifiers, search that file for the use of `removeCVRQualifiers`.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180818/5dcbc5c4/attachment.html>


More information about the cfe-dev mailing list