Skip to content

Commit dfe7b5e

Browse files
committed
c++: mutable temps in rodata [PR116369]
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. (cherry picked from commit 2801a49)
1 parent a82583e commit dfe7b5e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

gcc/cp/call.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13650,7 +13650,9 @@ set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **cleanups,
1365013650
init = cp_fully_fold (init);
1365113651
if (TREE_CONSTANT (init))
1365213652
{
13653-
if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
13653+
if (literal_type_p (type)
13654+
&& CP_TYPE_CONST_NON_VOLATILE_P (type)
13655+
&& !TYPE_HAS_MUTABLE_P (type))
1365413656
{
1365513657
/* 5.19 says that a constant expression can include an
1365613658
lvalue-rvalue conversion applied to "a glvalue of literal type
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// PR c++/116369
2+
// { dg-do run { target c++11 } }
3+
4+
struct f{
5+
mutable int t;
6+
};
7+
8+
const f &g = {1};
9+
10+
int main()
11+
{
12+
g.t++;
13+
}

0 commit comments

Comments
 (0)