https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119139
Bug ID: 119139
Summary: Regression with struct invariants
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: d
Assignee: ibuclaw at gdcproject dot org
Reporter: kkryukov at gmail dot com
Target Milestone: ---
A project started crashing after upgrading to a recent toolchain. I noticed
that commenting out invariants helps. I reduced it to the following:
import std.conv: to;
struct A
{
ulong n;
string str()
{
if (n == 0) { return "0"; }
return to!string(n);
}
}
struct B
{
ulong n;
invariant() {}
string str()
{
if (n == 0) { return "0"; }
return to!string(n);
}
}
void main()
{
A a = { 1 };
B b = { 2 };
assert(a.str() == "1"); // OK
assert(b.str() == "2"); // Fails
}
Compiled with "gdc -Og -o repro repro.d", using gdc (GCC) 14.2.1 20240912 (Red
Hat 14.2.1-3), on Linux.
Discussed in dlang forum (
https://forum.dlang.org/post/[email protected] ), where
people reported that this works fine in DMD, LDC, and older GDC.