* [Bug c++/105550] Missing copy elision with conditional operator in NSDMI
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
@ 2022-05-10 15:22 ` mpolacek at gcc dot gnu.org
2022-05-10 15:41 ` [Bug c++/105550] Missing copy elision with conditional operator mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-10 15:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Last reconfirmed| |2022-05-10
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Blocks| |100252
Ever confirmed|0 |1
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100252
[Bug 100252] [9/10/11/12/13 Regression] Internal compiler error during template
instantiation
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105550] Missing copy elision with conditional operator
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
2022-05-10 15:22 ` [Bug c++/105550] " mpolacek at gcc dot gnu.org
@ 2022-05-10 15:41 ` mpolacek at gcc dot gnu.org
2022-05-13 23:50 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-10 15:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Missing copy elision with |Missing copy elision with
|conditional operator in |conditional operator
|NSDMI |
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is not tied to NSDMIs; this one fails the same:
struct A {
const A* p = this;
};
constexpr A a = true ? A{} : A{};
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105550] Missing copy elision with conditional operator
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
2022-05-10 15:22 ` [Bug c++/105550] " mpolacek at gcc dot gnu.org
2022-05-10 15:41 ` [Bug c++/105550] Missing copy elision with conditional operator mpolacek at gcc dot gnu.org
@ 2022-05-13 23:50 ` mpolacek at gcc dot gnu.org
2022-07-01 16:11 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-13 23:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
// PR c++/105550
struct A {
const A *p = this;
};
struct B {
const B *p = this;
constexpr operator A() { return {}; }
};
struct E {
A a1 = true ? A{} : A{};
A a2 = true ? A{} : B{};
A a3 = false ? A{} : B{};
A a4 = false ? B{} : B{};
A a5 = A{};
A a6 = B{};
A a7 = false ? B{} : (true ? A{} : A{});
A a8 = false ? (true ? A{} : B{}) : (true ? A{} : A{});
};
constexpr E e{};
constexpr A
foo (A a)
{
return a;
}
constexpr A
bar (A)
{
return {};
}
constexpr A baz() { return {}; }
constexpr A a1 = true ? A{} : A{};
constexpr A a2 = true ? A{} : B{};
constexpr A a3 = false ? A{} : B{};
constexpr A a4 = false ? B{} : B{};
constexpr A a5 = A{};
constexpr A a6 = B{};
constexpr A a7 = false ? B{} : (true ? A{} : A{});
constexpr A a8 = false ? (true ? A{} : B{}) : (true ? A{} : A{});
constexpr A a9 = (A{});
constexpr A a10 = (true, A{});
constexpr A a11 = bar (A{});
//static_assert(a10.p == &a10, ""); // bug?
constexpr A a12 = baz ();
//static_assert(a11.p == &a11, ""); // bug?
//constexpr A a13 = foo (A{}); // error!
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105550] Missing copy elision with conditional operator
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
` (2 preceding siblings ...)
2022-05-13 23:50 ` mpolacek at gcc dot gnu.org
@ 2022-07-01 16:11 ` cvs-commit at gcc dot gnu.org
2022-07-01 16:12 ` mpolacek at gcc dot gnu.org
2022-10-31 18:08 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-01 16:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:ecd11acacd6be57af930fa617d7c31ecb40e7f74
commit r13-1397-gecd11acacd6be57af930fa617d7c31ecb40e7f74
Author: Marek Polacek <polacek@redhat.com>
Date: Wed May 25 18:11:31 2022 -0400
c++: fix broken copy elision with nested TARGET_EXPRs [PR105550]
In this problem, we are failing to properly perform copy elision with
a conditional operator, so this:
constexpr A a = true ? A{} : A{};
fails with:
error: 'A{((const A*)(&<anonymous>))}' is not a constant expression
The whole initializer is
TARGET_EXPR <D.2395, 1 ? TARGET_EXPR <D.2393, {.p=(const struct A *)
&<PLACEHOLDER_EXPR struct A>}> : TARGET_EXPR <D.2394, {.p=(const struct A *)
&<PLACEHOLDER_EXPR struct A>}>>
where the outermost TARGET_EXPR is elided, but not the nested ones.
Then we end up replacing the PLACEHOLDER_EXPRs with the temporaries the
TARGET_EXPRs represent, which is precisely what should *not* happen with
copy elision.
I've tried the approach of tweaking ctx->object, but I ran into gazillion
problems with that. I thought that I would let
cxx_eval_constant_expression
/TARGET_EXPR create a new object only when ctx->object was null, then
adjust setting of ctx->object in places like cxx_bind_parameters_in_call
and cxx_eval_component_reference but that failed completely. Sometimes
ctx->object has to be reset, sometimes it cannot be reset, 'this' needed
special handling, etc. I gave up.
Instead, this patch strips TARGET_EXPRs from the operands of ?: like
we do in various other places in constexpr.c.
PR c++/105550
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_conditional_expression): Strip
TARGET_EXPRs.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/nsdmi-aggr16.C: Remove FIXME.
* g++.dg/cpp1y/nsdmi-aggr17.C: Remove FIXME.
* g++.dg/cpp0x/constexpr-elision1.C: New test.
* g++.dg/cpp1y/constexpr-elision1.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105550] Missing copy elision with conditional operator
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
` (3 preceding siblings ...)
2022-07-01 16:11 ` cvs-commit at gcc dot gnu.org
@ 2022-07-01 16:12 ` mpolacek at gcc dot gnu.org
2022-10-31 18:08 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-01 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105550] Missing copy elision with conditional operator
2022-05-10 15:21 [Bug c++/105550] New: Missing copy elision with conditional operator in NSDMI mpolacek at gcc dot gnu.org
` (4 preceding siblings ...)
2022-07-01 16:12 ` mpolacek at gcc dot gnu.org
@ 2022-10-31 18:08 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-31 18:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105550
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 7+ messages in thread