Bug 19950 – access violation at compile time, possibly via template constraint and alias interaction
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-11T02:21:10Z
Last change time
2019-07-19T00:22:28Z
Keywords
ice, pull
Assigned to
No Owner
Creator
emmanuelle
Comments
Comment #0 by lakeavenger+dlangi — 2019-06-11T02:21:10Z
The following snippet causes an access violation at compile time on dmd v2.086, after a `test.d(2): Error: undefined identifier NotHere` error:
---
struct Bar {
alias Baz = NotHere;
static foreach (name; 0 .. 1) {
alias someAlias = set!();
}
void set()(Baz)
if (true)
{}
}
---
Changing any meaningful structure in the snippet, such as:
- removing the if guard in `set` (changing the condition seems fine)
- changing the arguments in `set`
- removing the static foreach (altering what it iterates over is fine, as long as it's not empty)
- changing what `someAlias` aliases to
makes compilation act as normal (failing but no access violation), so I assume this is a weird edge case with static foreach, if guards, and aliases.
Information DMD asked me to send:
---
DMD %.*s
predefs DigitalMars Windows CRuntime_DigitalMars CppRuntime_DigitalMars LittleEndian D_Version2 all D_InlineAsm D_InlineAsm_X86 X86 Win32 assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat
binary C:\D\dmd2\windows\bin\dmd.exe
version v2.086.0
config C:\D\dmd2\windows\bin\sc.ini
DFLAGS -IC:\D\dmd2\windows\bin\..\..\src\phobos -IC:\D\dmd2\windows\bin\..\..\src\druntime\import
---
run.dlang.io says the bug has been present ever since static foreach was introduced, in dmd v2.076. Before that, the code obviously fails to parse.
Comment #1 by lakeavenger+dlangi — 2019-06-11T02:33:44Z
Actually, it seems you can create an even tinier example:
---
alias Foo = NotHere;
alias Bar = baz!();
void baz()(Foo)
if (true)
{}
---
Which compiles fine (with a normal error) from dmd v2.060 until v2.066, but in v2.067 and v2.068 it has this cryptic error:
---
onlineapp.d(1): Error: undefined identifier NotHere
dmd: template.c:930: MATCH TemplateDeclaration::matchWithInstance(Scope*, TemplateInstance*, Objects*, Expressions*, int): Assertion `fd->type->ty == Tfunction' failed.
---
And from v2.069 onwards it has a segfault/access violation.
Comment #2 by dlang-bot — 2019-07-18T20:43:19Z
@Basile-z created dlang/dmd pull request #10195 "fix issue 19950 - access violation at compile time, possibly via template constraint and alias interaction" fixing this issue:
- fix issue 19950 - access violation at compile time, possibly via template constraint and alias interaction
https://github.com/dlang/dmd/pull/10195
Comment #3 by dlang-bot — 2019-07-19T00:22:28Z
dlang/dmd pull request #10195 "fix issue 19950 - access violation at compile time, possibly via template constraint and alias interaction" was merged into stable:
- 9cd97ab03969186b1d45c95a18abf8d43b6c40a1 by Basile Burg:
fix issue 19950 - access violation at compile time, possibly via template constraint and alias interaction
https://github.com/dlang/dmd/pull/10195