Bug 20795 – [dip1000] segfault on templated opEquals
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-03T17:38:06Z
Last change time
2020-05-04T11:42:41Z
Keywords
pull
Assigned to
No Owner
Creator
Sebastiaan Koppe
Comments
Comment #0 by mail — 2020-05-03T17:38:06Z
Compile following with `dmd -dip1000` and you get a segfault in dmd.func.FuncDeclaration.setUnsafe().
It has been reduced with dustmite so the code might not make sense. If the opEquals in Bar is converted from template to regular function we get a good error message, same with the opCast in Bar.
---
import std;
alias NamedArg = Tuple!Bar;
struct Foo
{
VariantN!24 variant;
bool opEquals(T)(T rhs) {
variant.opEquals(rhs);
}
}
struct Bar
{
bool opEquals()(Bar )
{
return Gun() == Foo.init;
}
}
class Baz {
T opCast(T)()
{
}
}
struct Gun
{
void[24] buff;
auto underlying() {
return cast(Baz)buff.ptr;
}
alias underlying this;
}
---
Comment #1 by moonlightsentinel — 2020-05-03T23:15:46Z
Reduced example:
struct Foo
{
void opEquals(T)(T rhs) if (T.init.opCast!string) {}
}
struct Bar
{
void opEquals()(Bar)
{
Gun() == Foo.init;
}
}
class Baz
{
void opCast(T)() {}
}
struct Gun
{
void[24] buff;
auto underlying()
{
return cast(Baz) buff.ptr;
}
alias underlying this;
}
struct Tuple
{
Bar expand;
void opEquals(R)(R) if (mixin("Tuple.init.expand == R.init")) {}
}
Comment #2 by moonlightsentinel — 2020-05-03T23:17:53Z
(In reply to moonlightsentinel from comment #1)
Tuple isn't required:
struct Foo
{
void opEquals(T)(T rhs) if (T.init.opCast!string) {}
}
struct Bar
{
void opEquals()(Bar)
{
Gun() == Foo.init;
}
}
class Baz
{
void opCast(T)() {}
}
struct Gun
{
void[24] buff;
auto underlying()
{
return cast(Baz) buff.ptr;
}
alias underlying this;
void opEquals(R)(R) if (mixin("Bar.init == R.init")) {}
}
Comment #3 by dlang-bot — 2020-05-04T09:28:21Z
@RazvanN7 created dlang/dmd pull request #11096 "Fix Issue 20795 - [dip1000] segfault on templated opEquals" fixing this issue:
- Fix Issue 20795 - [dip1000] segfault on templated opEquals
https://github.com/dlang/dmd/pull/11096
Comment #4 by dlang-bot — 2020-05-04T11:42:41Z
dlang/dmd pull request #11096 "Fix Issue 20795 - [dip1000] segfault on templated opEquals" was merged into stable:
- bb64fe491abd5f09ebd6aaabf4c7f47ec9a39c36 by RazvanN7:
Fix Issue 20795 - [dip1000] segfault on templated opEquals
https://github.com/dlang/dmd/pull/11096