Here we wrongly mark the reference temporary for g TREE_READONLY,
so it's put in .rodata and so we can't modify its subobject even
when the subobject is marked mutable. This is so since r9-869.
r14-1785 fixed a similar problem, but not in set_up_extended_ref_temp.
PR c++/116369
gcc/cp/ChangeLog:
* call.cc (set_up_extended_ref_temp): Don't mark a temporary
TREE_READONLY if its type is TYPE_HAS_MUTABLE_P.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/initlist-opt7.C: New test.
init = cp_fully_fold (init);
if (TREE_CONSTANT (init))
{
- if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
+ if (literal_type_p (type)
+ && CP_TYPE_CONST_NON_VOLATILE_P (type)
+ && !TYPE_HAS_MUTABLE_P (type))
{
/* 5.19 says that a constant expression can include an
lvalue-rvalue conversion applied to "a glvalue of literal type
--- /dev/null
+// PR c++/116369
+// { dg-do run { target c++11 } }
+
+struct f{
+ mutable int t;
+};
+
+const f &g = {1};
+
+int main()
+{
+ g.t++;
+}