public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-8427] c++: Fix comparison of fn() and ns::fn() [PR90711]
@ 2020-03-31 17:04 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-03-31 17:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0e66150084aa217811a5c45fb15e98d7ed3e8839

commit r9-8427-g0e66150084aa217811a5c45fb15e98d7ed3e8839
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 30 16:09:43 2020 -0400

    c++: Fix comparison of fn() and ns::fn() [PR90711]
    
    The resolution of CWG issue 1321 clarified that when deciding whether two
    expressions involving template parameters are equivalent, two dependent
    function calls where the function is named with an unqualified-id are
    considered to be equivalent if the name is the same, even if unqualified
    lookup finds different sets of functions.  We were wrongly treating
    qualified-ids the same way, so that EXISTS and test::EXISTS were considered
    to be equivalent even though they are looking up the name in different
    scopes.  This also causes a mangling bug, but I don't think it's safe to fix
    that for GCC 10; this patch just fixes the comparison.
    
    gcc/cp/ChangeLog
    2020-03-30  Jason Merrill  <jason@redhat.com>
    
            PR c++/90711
            * tree.c (cp_tree_equal) [CALL_EXPR]: Compare KOENIG_LOOKUP_P.
            (called_fns_equal): Check DECL_CONTEXT.

Diff:
---
 gcc/cp/ChangeLog                                 |  6 ++++
 gcc/cp/tree.c                                    | 14 ++++++++-
 gcc/testsuite/g++.dg/template/dependent-name14.C | 38 ++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 91c01f543a5..d46bcfc8c17 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-30  Jason Merrill  <jason@redhat.com>
+
+	PR c++/90711
+	* tree.c (cp_tree_equal) [CALL_EXPR]: Compare KOENIG_LOOKUP_P.
+	(called_fns_equal): Check DECL_CONTEXT.
+
 2020-03-27  Nathan Sidwell  <nathan@acm.org>
 
 	PR c++/84733
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 3f3583c825d..ff150245d72 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2402,6 +2402,8 @@ is_overloaded_fn (tree x)
 tree
 dependent_name (tree x)
 {
+  /* FIXME a dependent name must be unqualified, but this function doesn't
+     distinguish between qualified and unqualified identifiers.  */
   if (identifier_p (x))
     return x;
   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
@@ -3506,6 +3508,15 @@ called_fns_equal (tree t1, tree t2)
       if (name1 != name2)
 	return false;
 
+      /* FIXME dependent_name currently returns an unqualified name regardless
+	 of whether the function was named with a qualified- or unqualified-id.
+	 Until that's fixed, check that we aren't looking at overload sets from
+	 different scopes.  */
+      if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
+	  && (DECL_CONTEXT (get_first_fn (t1))
+	      != DECL_CONTEXT (get_first_fn (t2))))
+	return false;
+
       if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
 	targs1 = TREE_OPERAND (t1, 1);
       if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
@@ -3602,7 +3613,8 @@ cp_tree_equal (tree t1, tree t2)
       {
 	tree arg1, arg2;
 	call_expr_arg_iterator iter1, iter2;
-	if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
+	if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2)
+	    || !called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
 	  return false;
 	for (arg1 = first_call_expr_arg (t1, &iter1),
 	       arg2 = first_call_expr_arg (t2, &iter2);
diff --git a/gcc/testsuite/g++.dg/template/dependent-name14.C b/gcc/testsuite/g++.dg/template/dependent-name14.C
new file mode 100644
index 00000000000..52d2e72be35
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/dependent-name14.C
@@ -0,0 +1,38 @@
+// PR c++/90711
+// { dg-do compile { target c++11 } }
+
+namespace test {
+    void EXISTS(int);
+}
+
+template<typename... ARGS>
+struct stub_void {
+    typedef void type;
+};
+template<typename... ARGS>
+using stub_void_t = typename stub_void<ARGS...>::type;
+
+#if !defined(SUPPRESS)
+template<typename O, typename = void>
+struct has_to_string {
+    static constexpr bool value = false;
+};
+
+template<typename O>
+struct has_to_string<O, stub_void_t<decltype(EXISTS(O{}))>> {
+    static constexpr bool value = true;
+};
+#endif
+
+template<typename O, typename = void>
+struct has_std_to_string {
+    static constexpr bool value = false;
+};
+
+template<typename O>
+struct has_std_to_string<O, stub_void_t<decltype(test::EXISTS(O{}))>> {
+    static constexpr bool value = true;
+};
+
+static_assert (has_std_to_string<int>::value, "");
+


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-31 17:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31 17:04 [gcc r9-8427] c++: Fix comparison of fn() and ns::fn() [PR90711] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).