Bug 3983 – Regression(2.037): struct with == can't be member of struct with template opEquals
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-03-18T02:48:00Z
Last change time
2015-06-09T01:28:30Z
Keywords
diagnostic, patch, rejects-valid
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2010-03-18T02:48:16Z
struct Fug
{
bool opEquals(ref const Fug y) const {
return false;
}
}
struct Fig
{ // line 29
Fug f;
bool opEquals(Tdummy=void)(ref const Fig y) const {
return false;
}
bool opEquals(T: int)(T y) const {
return false;
}
}
void main() {
Fig fx, fy;
if (fx==2) {}
}
---
And the error message is nonsense:
bug.d(29): Error: function bug.Fig.opEquals conflicts with template bug.Fig.opEq
uals(Tdummy = void) at bug.d(31)
Worked in 2.036.
--------
// Workaround is to change Fug opEquals to:
bool opEquals(Tdummy=void)(ref const Fug y) const
Comment #1 by clugdbug — 2010-06-11T02:36:12Z
Problem is in struct.c, StructDeclaration::semantic(), line 497:
it tries to find an opEquals() function, and if not present, it builds one.
It should look for a template opEquals() also. If there's a template opEquals,
then creating a non-template opEquals will inevitably cause a naming conflict.
Dsymbol *s = search_function(this, Id::eq);
FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL;
+ TemplateDeclaration *td = s ? s->isTemplateDeclaration() : NULL;
if (fdx)
{
eq = fdx->overloadExactMatch(tfeqptr);
if (!eq)
fdx->error("type signature should be %s not %s", tfeqptr->toChars(), fdx->type->toChars());
}
- if (!eq)
+ if (!eq && !td)
eq = buildOpEquals(sc2);