val = TREE_OPERAND (t, 1);
if (TREE_CODE (t) == IF_STMT && !val)
val = void_node;
+ /* A TARGET_EXPR may be nested inside another TARGET_EXPR, but still
+ serve as the initializer for the same object as the outer TARGET_EXPR,
+ as in
+ A a = true ? A{} : A{};
+ so strip the inner TARGET_EXPR so we don't materialize a temporary. */
+ if (TREE_CODE (val) == TARGET_EXPR)
+ val = TARGET_EXPR_INITIAL (val);
return cxx_eval_constant_expression (ctx, val, lval, non_constant_p,
overflow_p, jump_target);
}
--- /dev/null
+// PR c++/105550
+// { dg-do compile { target c++11 } }
+
+template <typename, typename> struct pair {
+ constexpr pair(int, int) {}
+};
+template <typename _Tp, typename _Compare>
+pair<const _Tp &, const _Tp &> minmax(const _Tp &__a, const _Tp &__b,
+ _Compare) {
+ return 0 ? pair<const _Tp &, const _Tp &>(__b, __a)
+ : pair<const _Tp &, const _Tp &>(__a, __b);
+}
+typedef int value_type;
+typedef int compare_type;
+template pair<const value_type &, const value_type &>
+minmax(const value_type &, const value_type &, compare_type);
--- /dev/null
+// PR c++/105550
+// { dg-do compile { target c++14 } }
+
+struct A {
+ const A *p = this;
+};
+
+struct B {
+ const B *p = this;
+ constexpr operator A() const { return {}; }
+};
+
+constexpr A
+bar (A)
+{
+ return {};
+}
+
+constexpr A baz() { 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{});
+ A a9 = (A{});
+ A a10 = (true, A{});
+ A a11 = bar (A{});
+ A a12 = baz ();
+ A a13 = (A{}, A{});
+};
+
+constexpr E e{};
+
+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, 105619
+constexpr A a12 = baz ();
+//static_assert(a11.p == &a11, ""); // bug, 105619
+constexpr A a13 = (A{}, A{});
A d = true ? (false ? A{} : A{}) : (false ? A{} : A{});
};
-// FIXME: When fixing this, also fix nsdmi-aggr17.C.
-constexpr E e; // { dg-bogus "" "PR105550" { xfail *-*-* } }
-SA (e.a.p == &e.a); // { dg-bogus "" "PR105550" { xfail *-*-* } }
+constexpr E e;
+SA (e.a.p == &e.a);
E e1 = { };
A a = true ? A{x} : A{x};
};
-// FIXME: Doesn't work due to PR105550.
-//constexpr F f;
-//SA (f.a.p == &f.a);
+constexpr F f;
+SA (f.a.p == &f.a);
SA (e.x == 42);
F f2 = { };
F f3 = { 42 };