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.
This commit is contained in:
parent
a2058f5812
commit
ed7f9957bb
12
gcc/cp/pt.c
12
gcc/cp/pt.c
@ -22698,10 +22698,22 @@ get_template_base (tree tparms, tree targs, tree parm, tree arg,
|
||||
|
||||
applies. */
|
||||
if (rval && !same_type_p (r, rval))
|
||||
{
|
||||
/* [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;
|
||||
}
|
||||
|
37
gcc/testsuite/g++.dg/DRs/dr2303.C
Normal file
37
gcc/testsuite/g++.dg/DRs/dr2303.C
Normal file
@ -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{});
|
||||
}
|
Loading…
Reference in New Issue
Block a user