Hi!

The following testcase ICEs (since the addition of inline var support),
because the lambda contains PTRMEM_CST but finish_function is called for the
lambda quite early during parsing it (from finish_lambda_function) when
the containing class is still incomplete.  That means that during
genericization cplus_expand_constant keeps the PTRMEM_CST unmodified, but
later nothing lowers it when the class is finalized.
Using sizeof etc. on the class in such contexts is rejected by both g++ and
clang++, and when the PTRMEM_CST appears e.g. in static var initializers
rather than in functions, we handle it correctly because c_parse_final_cleanups
-> lower_var_init will handle those cplus_expand_constant when all classes
are already finalized.

The following patch fixes it by calling cplus_expand_constant again during
gimplification, as we are now unconditionally unit at a time, I'd think
everything that could be completed will be before we start gimplification.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-03-30  Jakub Jelinek  <ja...@redhat.com>

        PR c++/99790
        * cp-gimplify.c (cp_gimplify_expr): Handle PTRMEM_CST.

        * g++.dg/cpp1z/pr99790.C: New test.

--- gcc/cp/cp-gimplify.c.jj     2021-03-20 17:01:59.791040946 +0100
+++ gcc/cp/cp-gimplify.c        2021-03-29 14:27:37.532223156 +0200
@@ -660,6 +660,14 @@ cp_gimplify_expr (tree *expr_p, gimple_s
       ret = GS_UNHANDLED;
       break;
 
+    case PTRMEM_CST:
+      *expr_p = cplus_expand_constant (*expr_p);
+      if (TREE_CODE (*expr_p) == PTRMEM_CST)
+       ret = GS_ERROR;
+      else
+       ret = GS_OK;
+      break;
+
     case RETURN_EXPR:
       if (TREE_OPERAND (*expr_p, 0)
          && (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == INIT_EXPR
--- gcc/testsuite/g++.dg/cpp1z/pr99790.C.jj     2021-03-29 14:38:35.887814018 
+0200
+++ gcc/testsuite/g++.dg/cpp1z/pr99790.C        2021-03-29 14:37:41.828422188 
+0200
@@ -0,0 +1,9 @@
+// PR c++/99790
+// { dg-do compile { target c++17 } }
+
+struct A;
+struct B { void (*fn) (A *); };
+template <typename T>
+int foo (const T &);
+struct A { int a; static constexpr B b{[] (A *n) { n->*&A::a = 2; }}; };
+int a = foo (A::b);

        Jakub

Reply via email to