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

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 23 10:37:48 PDT 2016


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.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21653.61691.patch
Type: text/x-patch
Size: 6321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160623/96e58b5b/attachment.bin>


More information about the cfe-commits mailing list