[gcc r10-8853] c++: Fix up default initialization with consteval default ctor [PR96994]
Jakub Jelinek
jakub@gcc.gnu.org
Mon Oct 5 08:24:59 GMT 2020
https://gcc.gnu.org/g:2513dad670c00dd9db3a85be348f6f4020b18b81
commit r10-8853-g2513dad670c00dd9db3a85be348f6f4020b18b81
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Oct 1 11:18:35 2020 +0200
c++: Fix up default initialization with consteval default ctor [PR96994]
> > The following testcase is miscompiled (in particular the a and i
> > initialization). The problem is that build_special_member_call due to
> > the immediate constructors (but not evaluated in constant expression mode)
> > doesn't create a CALL_EXPR, but returns a TARGET_EXPR with CONSTRUCTOR
> > as the initializer for it,
>
> That seems like the bug; at the end of build_over_call, after you
>
> > call = cxx_constant_value (call, obj_arg);
>
> You need to build an INIT_EXPR if obj_arg isn't a dummy.
That works. obj_arg is NULL if it is a dummy from the earlier code.
2020-10-01 Jakub Jelinek <jakub@redhat.com>
PR c++/96994
* call.c (build_over_call): If obj_arg is non-NULL, return INIT_EXPR
setting obj_arg to call.
* g++.dg/cpp2a/consteval18.C: New test.
(cherry picked from commit 56da736cc6ced0f1c339744321a14ae569db8606)
Diff:
---
gcc/cp/call.c | 2 ++
gcc/testsuite/g++.dg/cpp2a/consteval18.C | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 0206e8d5b99..212f23b4a88 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9175,6 +9175,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
}
}
call = cxx_constant_value (call, obj_arg);
+ if (obj_arg && !error_operand_p (call))
+ call = build2 (INIT_EXPR, void_type_node, obj_arg, call);
}
}
return call;
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval18.C b/gcc/testsuite/g++.dg/cpp2a/consteval18.C
new file mode 100644
index 00000000000..586feded505
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval18.C
@@ -0,0 +1,26 @@
+// PR c++/96994
+// { dg-do run { target c++20 } }
+
+struct A { consteval A () { i = 1; } consteval A (int x) : i (x) {} int i = 0; };
+struct B { constexpr B () { i = 1; } constexpr B (int x) : i (x) {} int i = 0; };
+A const a;
+constexpr A b;
+B const c;
+A const constinit d;
+A const e = 2;
+constexpr A f = 3;
+B const g = 4;
+A const constinit h = 5;
+A i;
+B j;
+A k = 6;
+B l = 7;
+static_assert (b.i == 1 && f.i == 3);
+
+int
+main()
+{
+ if (a.i != 1 || c.i != 1 || d.i != 1 || e.i != 2 || g.i != 4 || h.i != 5
+ || i.i != 1 || j.i != 1 || k.i != 6 || l.i != 7)
+ __builtin_abort ();
+}
More information about the Gcc-cvs
mailing list