Bug 19731 – auto struct methods whose address is taken don't test invariants

Status
REOPENED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-03-12T14:10:55Z
Last change time
2024-12-13T19:02:33Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#17899 →

Comments

Comment #0 by default_357-line — 2019-03-12T14:10:55Z
Consider the following code: struct Foo { Object obj_; invariant (obj_ !is null); auto obj() { return this.obj_; } enum compiles = __traits(compiles, &Foo.init.obj); } void main() { Foo foo = Foo(); foo.obj.toString(); } foo.obj should hit the invariant, but because Foo.obj straight up does not call the invariant check at all, we instead hit a segfault in toString. The code works if the return type is not auto, or if the `enum compiles` line is removed.
Comment #1 by default_357-line — 2019-03-12T14:36:12Z
The combination of return type inference and taking the address forces DMD to run semantic3 where invariants are not yet available, and there's no way to say "we want to rerun semantic3 later, this is just a throwaway run".
Comment #2 by b2.temp — 2019-03-12T15:10:52Z
I get an ICE with 2.085 or git ~master, run.dlang.io shows that in addition the ICE is a 2.077.z regression : https://run.dlang.io/is/sT3LTT
Comment #3 by b2.temp — 2019-03-12T15:12:55Z
My bad, it's the program that crashes, not dmd.
Comment #4 by dlang-bot — 2019-03-12T15:30:11Z
@FeepingCreature created dlang/dmd pull request #9448 "Fix Issue 19731: throw away semantic3 run after return type inference to avoid missing invariants" fixing this issue: - Fix Issue 19731: throw away semantic3 run after return type inference to avoid missing invariants https://github.com/dlang/dmd/pull/9448
Comment #5 by default_357-line — 2019-03-12T16:07:19Z
Okay, naively copying the method, running semantic3 and copying the type back does not work. Darn.
Comment #6 by dlang-bot — 2019-03-19T13:09:28Z
@RazvanN7 created dlang/dmd pull request #9467 "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants" fixing this issue: - Fix Issue 19731 - auto struct methods whose address is taken don't test invariants https://github.com/dlang/dmd/pull/9467
Comment #7 by dlang-bot — 2019-03-20T10:13:24Z
dlang/dmd pull request #9467 "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants" was merged into master: - 3f52528e2dd40f116202dac1a8e4d34326c5bc3b by RazvanN7: Fix Issue 19731 - auto struct methods whose address is taken don't test invariants https://github.com/dlang/dmd/pull/9467
Comment #8 by ibuclaw — 2019-08-22T20:41:10Z
Not fixed, as the bug still occurs if you compile the original test with -inline.
Comment #9 by dlang-bot — 2021-06-29T10:19:19Z
@ibuclaw created dlang/dmd pull request #12783 "Revert "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants"" mentioning this issue: - Revert "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants" This reverts commit 3f52528e2dd40f116202dac1a8e4d34326c5bc3b. - test: Add regression tests to prevent breakages from fixing issue 19731 https://github.com/dlang/dmd/pull/12783
Comment #10 by dlang-bot — 2021-06-29T11:21:32Z
dlang/dmd pull request #12783 "Revert "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants"" was merged into master: - bab51bf8a665209400ecf0efa41bb76bc01d12c9 by Iain Buclaw: Revert "Fix Issue 19731 - auto struct methods whose address is taken don't test invariants" This reverts commit 3f52528e2dd40f116202dac1a8e4d34326c5bc3b. - 7911d48258166c391adc0528a561ee0cd5e4946e by Iain Buclaw: test: Add regression tests to prevent breakages from fixing issue 19731 https://github.com/dlang/dmd/pull/12783
Comment #11 by robert.schadek — 2024-12-13T19:02:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17899 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB