[PATCH] D21653: [Sema] Disallow ambiguous base-to-derived conversion in template argument deduction

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 14:24:53 PDT 2016


On Thu, Jun 23, 2016 at 10:37 AM, Erik Pilkington via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> erik.pilkington created this revision.
> erik.pilkington added reviewers: rsmith, faisalv.
> erik.pilkington added a subscriber: cfe-commits.
>
> Previously, Clang would incorrectly accept the following:
> ```
> template<int N> struct A {};
> struct B : A<0>, A<1> {};
> template<int N> int f(A<N>);
> int main() { f(B()); }
> ```
> The problem is that when considering the base classes of B, there are 2
> possible ambiguous bases that could be deduced. Therefore, deduction ought
> to fail (temp.deduct.call p5).
>
> There are 3 improvements that I want to make here as well:
>  1. Introduce a TDK_AmbiguousBaseClasses so that this diagnostic isn't
> terrible.
>  2. Reapply Richard's r267453, (with some modifications) which previously
> broke stdlibc++'s tuple implementation (PR27601, reverted in r270016). This
> refactors the handmade base class traversal I fixed here to instead use
> CXXRecordDecl::forallBases(), I believe that requiring matching number of
> arguments in the DeduceTemplateArguments at SemaTemplateDeduction.cpp:433
> will fix it.
>  3. A NFC patch to rename the 10 (!) overloads of DeduceTemplateArguments
> to have more descriptive names. These functions are *really* annoying to
> deal with because of that.
>

I would love to see these as follow-up changes :)


> If it would be better to do a subset (or all) of these improvements here,
> I could always update the diff. Fixes PR28195.
>
> Thanks!
>
> http://reviews.llvm.org/D21653
>
> Files:
>   lib/Sema/SemaTemplateDeduction.cpp
>   test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160628/c67ff0df/attachment.html>


More information about the cfe-commits mailing list