+2019-12-07 Jason Merrill <jason@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ 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 <jakub@redhat.com>
* parser.c (cp_parser_diagnose_invalid_type_name): Mention
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);
--- /dev/null
+// PR c++/92831
+// { dg-do run { target c++11 } }
+// { dg-options "" }
+
+template<typename T> 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<S[3]>{false, true, false}[i].s
+ ? id<S[2]>{true, false}[i].s : id<S[4]>{true, false, true, false}[i].s;
+ if (S::c != (i ? 2 : 4))
+ __builtin_abort ();
+}
+
+void
+baz (int i)
+{
+ const bool&& a = id<S[3]>{false, true, false}[i].s
+ ? : id<S[4]>{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 ();
+}