With my fix for PR c++/21802 I changed build_min_non_dep_call_vec() to
additionally retain the KOENIG_LOOKUP_P flag of the non-dependent
expression that's been built.  This change was a little too general
though, since retaining the KOENIG_LOOKUP_P flag is only necessary for
build_min_non_dep_op_overload(), which builds a CALL_EXPR to an operator
overload -- other callers of build_min_non_dep_call_vec() do not need or
expect this to be done.

So this patch moves this KOENIG_LOOKUP_P flag retention from
build_min_non_dep_call_vec() to build_min_non_dep_op_overload(), the
only place where it's needed and where we are sure that NON_DEP is a
CALL_EXPR.

Bootstrap and regtest in progress on x86_64-pc-linux-gnu, OK to commit
after testing?

gcc/cp/ChangeLog:

        PR c++/68936
        * tree.c (build_min_non_dep_call_vec): Don't retain the
        KOENIG_LOOKUP_P flag of the non-dependent expression that's
        been built.
        (build_min_non_dep_op_overload): Instead, do it here.

gcc/testsuite/ChangeLog:

        PR c++/68936
        * g++.dg/template/pr68936.C: New test.
---
 gcc/cp/tree.c                           |  6 +++++-
 gcc/testsuite/g++.dg/template/pr68936.C | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/pr68936.C

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index d679889..e2123ac 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2747,7 +2747,6 @@ build_min_non_dep_call_vec (tree non_dep, tree fn, 
vec<tree, va_gc> *argvec)
     non_dep = TREE_OPERAND (non_dep, 0);
   TREE_TYPE (t) = TREE_TYPE (non_dep);
   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
-  KOENIG_LOOKUP_P (t) = KOENIG_LOOKUP_P (non_dep);
   return convert_from_reference (t);
 }
 
@@ -2810,6 +2809,11 @@ build_min_non_dep_op_overload (enum tree_code op,
   call = build_min_non_dep_call_vec (non_dep, fn, args);
   release_tree_vector (args);
 
+  tree call_expr = call;
+  if (REFERENCE_REF_P (call_expr))
+    call_expr = TREE_OPERAND (call_expr, 0);
+  KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
+
   return call;
 }
 
diff --git a/gcc/testsuite/g++.dg/template/pr68936.C 
b/gcc/testsuite/g++.dg/template/pr68936.C
new file mode 100644
index 0000000..ecfc09e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr68936.C
@@ -0,0 +1,20 @@
+// PR c++/68936
+
+class A {};
+
+struct predefined_macros {
+  struct B {
+    A (predefined_macros::*generator)();
+  };
+};
+
+template <typename> class C {
+  void m_fn1();
+  predefined_macros predef;
+};
+
+predefined_macros::B m;
+
+template <typename ContextT> void C<ContextT>::m_fn1() {
+  (predef.*m.generator)();
+}
-- 
2.7.0.83.gdfccd77.dirty

Reply via email to