diff options
author | Jason Merrill <jason@redhat.com> | 2019-12-10 15:12:50 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2019-12-10 15:12:50 -0500 |
commit | eff66cd2aa4e6cbce289ce61aa903ed3ee4b52fa (patch) | |
tree | e7e2454d6723bc9e7cd9b780d1fc4abdf0820bbf | |
parent | 09b661cea17a144e68009ecdf61a92a05bf852dd (diff) | |
download | gcc-eff66cd2aa4e6cbce289ce61aa903ed3ee4b52fa.zip gcc-eff66cd2aa4e6cbce289ce61aa903ed3ee4b52fa.tar.gz gcc-eff66cd2aa4e6cbce289ce61aa903ed3ee4b52fa.tar.bz2 |
PR c++/92847 - C++20 comparison ambiguity with class template.
This testcase demonstrates that looking at cand->template_decl is not a good
starting place for finding the most general template, as it is only set for
primary templates.
* call.c (cand_parms_match): Handle all templated functions.
From-SVN: r279185
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/call.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite5.C | 15 |
3 files changed, 33 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6b15fc3..c776054 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2019-12-10 Jason Merrill <jason@redhat.com> + PR c++/92847 - C++20 comparison ambiguity with class template. + * call.c (cand_parms_match): Handle all templated functions. + Fix C++20 structural type vs. private base. * class.c (build_base_field_1): Take access parameter. (build_base_field): Likewise. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 48d49b7..cbd5747 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -11052,24 +11052,25 @@ joust_maybe_elide_copy (z_candidate *&cand) bool cand_parms_match (z_candidate *c1, z_candidate *c2) { - tree fn1 = c1->template_decl; - tree fn2 = c2->template_decl; - if (fn1 && fn2) - { - fn1 = most_general_template (TI_TEMPLATE (fn1)); - fn1 = DECL_TEMPLATE_RESULT (fn1); - fn2 = most_general_template (TI_TEMPLATE (fn2)); - fn2 = DECL_TEMPLATE_RESULT (fn2); - } - else - { - fn1 = c1->fn; - fn2 = c2->fn; - } + tree fn1 = c1->fn; + tree fn2 = c2->fn; if (fn1 == fn2) return true; if (identifier_p (fn1) || identifier_p (fn2)) return false; + /* We don't look at c1->template_decl because that's only set for primary + templates, not e.g. non-template member functions of class templates. */ + tree t1 = most_general_template (fn1); + tree t2 = most_general_template (fn2); + if (t1 || t2) + { + if (!t1 || !t2) + return false; + if (t1 == t2) + return true; + fn1 = DECL_TEMPLATE_RESULT (t1); + fn2 = DECL_TEMPLATE_RESULT (t2); + } return compparms (TYPE_ARG_TYPES (TREE_TYPE (fn1)), TYPE_ARG_TYPES (TREE_TYPE (fn2))); } diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite5.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite5.C new file mode 100644 index 0000000..d042437 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite5.C @@ -0,0 +1,15 @@ +// { dg-do compile { target c++11 } } + +template<typename T> +struct A { + A() {} + + template<typename U> + A(const A<U>&) {} + + bool operator==(const A&) const { return true; } +}; + +A<const int> a; +A<int> b; +auto c = (a == b); |