November 11, 2023
https://issues.dlang.org/show_bug.cgi?id=24240

          Issue ID: 24240
           Summary: Missing @nogc compile error in -betterC leads to
                    undefined reference linker error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: andy.pj.hanson@gmail.com

```
@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.

--