[PATCH] D133683: [c++] implements tentative DR1432 for partial ordering of function template

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 18 09:53:38 PDT 2022


ychen added inline comments.


================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5179-5231
   if (!Better1 && !Better2) // Neither is better than the other
     return JudgeByConstraints();
 
   // C++ [temp.deduct.partial]p11:
   //   ... and if G has a trailing function parameter pack for which F does not
   //   have a corresponding parameter, and if F does not have a trailing
   //   function parameter pack, then F is more specialized than G.
----------------
mizvekov wrote:
> One thing I have been thinking about all of these "more constrained" checks, is whether we should actually be performing them over the results of the deductions for the least constrained checks.
> 
> Ie especially with regards to this new check and the one for `[temp.deduct.partial]p11:`, it seems that we should be instead considering as more constrained the deduction which deduced a lesser amount of template parameters, including ones in packs. Or something along this line.
> 
> This way, we do one sweeping general rule to handle all these cases, instead of just appending these ad-hoc tie-breaking rules which look more like workarounds.
> 
> What do you think about that?
> 
> But this is a big change and I don't want to block you on that. Because otherwise, this new change is keeping in line with other workarounds that have already been added here, so this is within existing practice.
> 
> Since this patch was submitted quite recently and it's a speculative fix, I would let this patch marinate a little more and wait for any other reviewers.
> Ie especially with regards to this new check and the one for [temp.deduct.partial]p11:, it seems that we should be instead considering as more constrained the deduction which deduced a lesser amount of template parameters, including ones in packs. Or something along this line.
>
>This way, we do one sweeping general rule to handle all these cases, instead of just appending these ad-hoc tie-breaking rules which look more like workarounds.
>
> What do you think about that?

I think you meant the cases that for a  `P`/`A` deduction pair, either `P`/`A` is pack and the other is not empty, right? If so, it already works that way. https://eel.is/c++draft/temp.deduct#type-9

If neither `P`/`A` is pack and either is empty, then they wouldn't get into the stage of partial ordering at all because the function arguments list can only have one length,  `P`/`A` would not be in the same candidate sets.

Here handles the case that either  `P`/`A` is pack and the other is empty. Then the deduction rule could not kick in because one of the `P`/`A`pair is none. So we have to tie-break after the deduction.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133683/new/

https://reviews.llvm.org/D133683



More information about the cfe-commits mailing list