diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 88dc5251bda..1bad1866763 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -1323,7 +1323,7 @@ get_symbol_decl (Declaration *decl) /* `const` applies to data that cannot be changed by the const reference to that data. It may, however, be changed by another reference to that same data. */ - if (vd->isConst () && !vd->isDataseg ()) + if (vd->isConst () && !vd->isResult () && !vd->isDataseg ()) TREE_READONLY (decl->csym) = 1; } diff --git a/gcc/testsuite/gdc.dg/pr119139.d b/gcc/testsuite/gdc.dg/pr119139.d new file mode 100644 index 00000000000..dc42c411e39 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr119139.d @@ -0,0 +1,24 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139 +// { dg-do compile } +// { dg-options "-fdump-tree-gimple" } +string toString() +{ + return "1"; +} + +struct B +{ + ulong n; + + invariant{} + + string str() + { + if (n == 0) + { + return "0"; + } + return toString(); + } +} +// { dg-final { scan-tree-dump-not "static const struct __result =" "gimple" } }