The case in the ticket is an ICE on invalid due to an assert in stabilize_expr,
but the underlying issue can actually trigger on this *valid* code:
=== cut here ===
struct TheClass {
TheClass() {}
TheClass(volatile TheClass& t) {}
TheClass operator=(volatile TheClass& t) volatile { return t; }
};
void the_func() {
volatile TheClass x, y, z;
(false ? x : y) = z;
}
=== cut here ===
The problem is that stabilize_expr asserts that it returns an expression
without TREE_SIDE_EFFECTS, which can't be if the involved type is volatile.
This patch relaxes the assert to accept having TREE_THIS_VOLATILE on the
returned expression.
Successfully tested on x86_64-pc-linux-gnu.
PR c++/111160
gcc/cp/ChangeLog:
* tree.cc (stabilize_expr): Stabilized expressions can have
TREE_SIDE_EFFECTS if they're volatile.
gcc/testsuite/ChangeLog:
* g++.dg/overload/error8.C: New test.
* g++.dg/overload/volatile2.C: New test.
}
*initp = init_expr;
- gcc_assert (!TREE_SIDE_EFFECTS (exp));
+ gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
return exp;
}
--- /dev/null
+// PR c++/111160
+// { dg-do compile { target c++11 } }
+
+class TheClass {}; // { dg-error "discards|bind|discards|bind" }
+void the_func() {
+ TheClass x;
+ volatile TheClass y;
+ (false ? x : x) = y; // { dg-error "ambiguous|ambiguous" }
+}
--- /dev/null
+// PR c++/111160
+// { dg-do compile { target c++11 } }
+
+struct TheClass {
+ TheClass() {}
+ TheClass(volatile TheClass& t) {}
+ TheClass operator=(volatile TheClass& t) volatile { return t; }
+};
+void the_func() {
+ volatile TheClass x, y, z;
+ (false ? x : y) = z;
+}