mizvekov 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.
----------------
ychen wrote:
> 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.
I understand we need to tie break after the at-least-as-specialized check, but 
I was wondering if we could come up with one sweeping rule / mechanism, which 
incorporates not only these two cases but also the concept more-constrained 
check, instead of appending multiple completely separate tie breakers.

Otherwise, I think this gets pretty hard to incorporate into your mental model 
of what overload resolution should pick up and such.

For example, even the order which we tie break seems arbitrary, and this makes 
it harder for folks to learn / memorize them and for them to actually be 
useful, instead of just programming traps. But this is C++ so I may be barking 
at the wrong tree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133683

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to