diff options
author | kamlesh kumar <kamleshbhalui@gmail.com> | 2020-11-02 20:40:21 +0530 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-11-03 14:36:24 -0500 |
commit | ed7f9957bbb5e899099e1ef0e5f6234c453ef7da (patch) | |
tree | e234f66f71aead87f0e5a3feab0f35759ee690ef /gcc | |
parent | a2058f5812bea3673859a68f9bfea61dbce6730f (diff) | |
download | gcc-ed7f9957bbb5e899099e1ef0e5f6234c453ef7da.zip gcc-ed7f9957bbb5e899099e1ef0e5f6234c453ef7da.tar.gz gcc-ed7f9957bbb5e899099e1ef0e5f6234c453ef7da.tar.bz2 |
c++: DR2303, ambiguous base deduction [PR97453]
When there are two possible matches and one is a base of the other, choose
the derived class rather than fail.
gcc/cp/ChangeLog
2020-10-21 Kamlesh Kumar <kamleshbhalui@gmail.com>
Jason Merrill <jason@redhat.com>
PR c++/97453
DR2303
* pt.c (get_template_base): Consider closest base in template
deduction when base of base also matches.
gcc/testsuite/ChangeLog
2020-10-21 Kamlesh Kumar <kamleshbhalui@gmail.com>
* g++.dg/DRs/dr2303.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/pt.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/DRs/dr2303.C | 37 |
2 files changed, 51 insertions, 2 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b782fb5..f401c75 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22699,8 +22699,20 @@ get_template_base (tree tparms, tree targs, tree parm, tree arg, applies. */ if (rval && !same_type_p (r, rval)) { - *result = NULL_TREE; - return tbr_ambiguous_baseclass; + /* [temp.deduct.call]/4.3: If there is a class C that is a + (direct or indirect) base class of D and derived (directly or + indirectly) from a class B and that would be a valid deduced + A, the deduced A cannot be B or pointer to B, respectively. */ + if (DERIVED_FROM_P (r, rval)) + /* Ignore r. */ + continue; + else if (DERIVED_FROM_P (rval, r)) + /* Ignore rval. */; + else + { + *result = NULL_TREE; + return tbr_ambiguous_baseclass; + } } rval = r; diff --git a/gcc/testsuite/g++.dg/DRs/dr2303.C b/gcc/testsuite/g++.dg/DRs/dr2303.C new file mode 100644 index 0000000..b6acb6e --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2303.C @@ -0,0 +1,37 @@ +// DR 2303 +// PR c++/97453 +// { dg-do compile { target c++11 } } + +template <typename... T> struct A; +template <> struct A<> +{ +}; +template <typename T, typename... Ts> struct A<T, Ts...> : A<Ts...> +{ +}; +struct B : A<int, int> +{ +}; + +struct C : A<int, int>, A<int> // { dg-warning "direct base .A<int>. inaccessible in .C. due to ambiguity" } +{ +}; + +struct D : A<int>, A<int, int> // { dg-warning "direct base .A<int>. inaccessible in .D. due to ambiguity" } +{ +}; +template <typename... T> +void +f (const A<T...> &) +{ + static_assert (sizeof...(T) == 2, "it should duduce to A<int,int>"); +} + + +void +g () +{ + f (B{}); + f (C{}); + f (D{}); +} |