From: Jakub Jelinek Date: Fri, 6 Dec 2019 23:43:45 +0000 (+0100) Subject: re PR c++/92831 (CWG1299 extend_ref_init_temps_1 punts on COND_EXPRs) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=beefe639b25eb9855a12b1d1436bbbc6b88ac78e;p=gcc.git re PR c++/92831 (CWG1299 extend_ref_init_temps_1 punts on COND_EXPRs) PR c++/92831 * call.c (build_conditional_expr_1): For ?: with omitted middle operand use cp_stabilize_reference if arg1 is glvalue_p rather than just if it is lvalue_p. * g++.dg/ext/temp-extend1.C: New test. From-SVN: r279069 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b4bdb894ecf..5cb63da5a88 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-12-07 Jason Merrill + Jakub Jelinek + + PR c++/92831 + * call.c (build_conditional_expr_1): For ?: with omitted middle + operand use cp_stabilize_reference if arg1 is glvalue_p rather than + just if it is lvalue_p. + 2019-12-06 Jakub Jelinek * parser.c (cp_parser_diagnose_invalid_type_name): Mention diff --git a/gcc/cp/call.c b/gcc/cp/call.c index af36f5f919e..ce942977f45 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5077,7 +5077,7 @@ build_conditional_expr_1 (const op_location_t &loc, warn_for_omitted_condop (loc, arg1); /* Make sure that lvalues remain lvalues. See g++.oliva/ext1.C. */ - if (lvalue_p (arg1)) + if (glvalue_p (arg1)) arg2 = arg1 = cp_stabilize_reference (arg1); else arg2 = arg1 = cp_save_expr (arg1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3c59ce91f1a..460cff00dd1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-07 Jakub Jelinek + + PR c++/92831 + * g++.dg/ext/temp-extend1.C: New test. + 2019-12-06 Marek Polacek PR c++/92451 diff --git a/gcc/testsuite/g++.dg/ext/temp-extend1.C b/gcc/testsuite/g++.dg/ext/temp-extend1.C new file mode 100644 index 00000000000..7df9ca51681 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/temp-extend1.C @@ -0,0 +1,43 @@ +// PR c++/92831 +// { dg-do run { target c++11 } } +// { dg-options "" } + +template using id = T; +struct S { S () : s (false) { ++c; } S (bool x) : s (x) { ++c; } ~S () { --c; }; bool s; static int c; }; +int S::c = 0; + +void +foo (int i) +{ + const bool&& a + = id{false, true, false}[i].s + ? id{true, false}[i].s : id{true, false, true, false}[i].s; + if (S::c != (i ? 2 : 4)) + __builtin_abort (); +} + +void +baz (int i) +{ + const bool&& a = id{false, true, false}[i].s + ? : id{true, false, true, false}[i].s; + if (S::c != (i ? 3 : 4)) + __builtin_abort (); +} + +int +main () +{ + foo (0); + if (S::c != 0) + __builtin_abort (); + foo (1); + if (S::c != 0) + __builtin_abort (); + baz (0); + if (S::c != 0) + __builtin_abort (); + baz (1); + if (S::c != 0) + __builtin_abort (); +}