Bug 22050 – -betterC: TypeInfo in speculative template instantiation aborts compilation without error message
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-20T07:07:47Z
Last change time
2023-01-15T07:52:03Z
Keywords
betterC
Assigned to
No Owner
Creator
mipri
Comments
Comment #0 by mipri — 2021-06-20T07:07:47Z
This program fails to compile with no output from dmd:
```
import std.algorithm, std.range, std.conv;
void foo() {
assert(2 == iota(2).map!(n => to!string(n)).length);
}
```
Shell session:
```
$ dmd -c bclife.d || echo failed
$ dmd -betterC -c bclife.d || echo failed
failed
$ dmd -betterC -c bclife.d -v |tail -1
import core.internal.lifetime (/home/mipri/dmd2/linux/bin64/../../src/druntime/import/core/internal/lifetime.d)
```
This behavior is seen also with a just-compiled devel dmd.
s/string/float/ and it's fine.
it silently crashes elsewhere with "".dup instead of to!string(n):
```
semantic2 bclife3
semantic3 bclife3
import core.stdc.string (/home/mipri/dmd2/linux/bin64/../../src/druntime/import/core/stdc/string.d
```
Most other variations that I've tried hit expected betterC errors.
Comment #1 by moonlightsentinel — 2021-06-20T19:19:16Z
DMD doesn't actually crash but aborts the compilation because of a hidden error (TypeInfo used in dup). The error message is not printed because the instantiation occurs in a speculative context.
Reduced example:
============================================
__gshared val = __traits(compiles, to!());
void to()()
{
auto ti = typeid(char[]);
}
============================================
dmd -c -o- -betterC -verrors=spec test.d
(spec:1) test.d(6): Error: `TypeInfo` cannot be used with -betterC
Comment #2 by bugzilla — 2023-01-15T07:52:03Z
The program:
import std.algorithm, std.range, std.conv;
void foo() {
assert(2 == iota(2).map!(n => to!string(n)).length);
}
extern (C) void main() { foo(); }
now compiles and runs successfully with -betterC on master.