Bug 24240 – Missing @nogc compile error in -betterC leads to undefined reference linker error

Status
NEW
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-11-11T14:39:37Z
Last change time
2024-12-13T19:31:43Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20356 →

Comments

Comment #0 by andy-hanson — 2023-11-11T14:39:37Z
``` @nogc: extern(C) void main() { foo(); } void foo() { bar([1]); } void bar(int[]) {} ``` Compiling with `dmd a.d`, it correctly fails with: ``` a.d(8): Error: array literal in `@nogc` function `a.foo` may cause a GC allocation ``` Compiling with `dmd -betterC a.d`, there is no compile error. Instead there is a linker error: ``` /usr/bin/ld: a.o: in function `main': a.d:(.text.main[main]+0x5): undefined reference to `_D1a3fooFNiZv' collect2: error: ld returned 1 exit status Error: linker exited with status 1 ``` I don't see a good reason not to have a compile error with `-betterC`. The linker error is harder to diagnose.
Comment #1 by robert.schadek — 2024-12-13T19:31:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20356 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB