[cfe-dev] Template Qualifier Removal Question
John McCall via cfe-dev
cfe-dev at lists.llvm.org
Wed Aug 15 01:27:39 PDT 2018
> 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.
More information about the cfe-dev
mailing list