Here, cp_tree_equal was assuming that the member operand of
COMPONENT_REF will be == if it is equivalent; that isn't accurate for
a reference to a member function.  So let's remove the special case
and fall back on normal expression handling.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.
commit a4a899baf962a73d81ae776ab3a7d80ea0a5bf8b
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jun 29 15:15:48 2017 -0400

            PR c++/81188 - matching decltype of member function call.
    
            * tree.c (cp_tree_equal): Remove COMPONENT_REF special case.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 4535af6..a52a9e8 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3589,11 +3589,6 @@ cp_tree_equal (tree t1, tree t2)
        return false;
       return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
 
-    case COMPONENT_REF:
-      if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
-       return false;
-      return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
-
     case PARM_DECL:
       /* For comparing uses of parameters in late-specified return types
         with an out-of-class definition of the function, but can also come
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-call4.C 
b/gcc/testsuite/g++.dg/cpp0x/decltype-call4.C
new file mode 100644
index 0000000..d504954
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype-call4.C
@@ -0,0 +1,13 @@
+// PR c++/81188
+// { dg-do compile { target c++11 } }
+
+template <class F>
+struct C {
+  F fast(long i) const;
+  auto operator[](long i) const -> decltype(this->fast(i));
+};
+
+template <class F>
+auto C<F>::operator[](long i) const -> decltype(this->fast(i)) {
+  return fast(i);
+}

Reply via email to