[Issue 24240] New: Missing @nogc compile error in -betterC leads to undefined reference linker error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 11 14:39:37 UTC 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 at puremagic.com
          Reporter: andy.pj.hanson at 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.

--


More information about the Digitalmars-d-bugs mailing list