Bug 3119 – Segfault(expression.c) template function overloads with function with same name in other module
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-06-30T23:40:00Z
Last change time
2015-06-09T01:27:57Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2009-06-30T23:40:15Z
In the code below the compiler will "Segmentation fault." getopt takes a string[], but is being given just a string. With the included import to std.c.linux.linux DMD will end with a segfault rather than the appropriate error message. Removing the import works as expected.
import std.c.linux.linux;
import std.getopt;
string arg1;
void main(string[] args) {
}
void parseArgs(ref string args) {
getopt(args, "f|file", &arg1);
}
Comment #1 by clugdbug — 2009-10-08T05:09:51Z
Can someone please (1) check that this fails; and
(2) reduce the test case?
Need to work out which part of std.c.linux.linux is triggering it. Probably isn't Linux specific, unless it's crashing in the code generation step.
Comment #2 by clugdbug — 2009-10-09T05:23:42Z
Reduced test case. Applies on any OS (not Linux specific), but D2 only since it
involves overload sets.
Import order is important! If order of imports is swapped, generates "Error:
expected 1 function arguments, not 0".
Segfaulting in CallExp::semantic(). e1->type is garbage. (not NULL, garbage!)
----
import bugB;
import bugC;
void main() { foo(); }
----
bugB.d:
----
void foo(int) {}
---
bugC.d:
---
void foo(T)(){}
Comment #3 by clugdbug — 2009-10-09T07:36:36Z
ANALYSIS:
expression.c, line 6693:
if (!f)
{ /* No overload matches, just set f and rely on error
* message being generated later.
*/
f = (FuncDeclaration *)eo->vars->a.data[0];
}
This is wrong because it's not necessarily a FuncDeclaration, it could be a TemplateDeclaration instead. I think an error message needs to be generated immediately.
Change this to something like:
if (!f)
{ /* No overload matches, just set f and rely on error
* message being generated later.
*/
error("no overload matches %s", savedFuncName);
return this;
}
after having added to line 6320 something like:
istemp = 0;
Lagain:
+ char *savedFuncName = toChars();
//printf("Lagain: %s\n", toChars());
f = NULL;
if (e1->op == TOKthis || e1->op == TOKsuper)
{
// semantic() run later for these
}
else
{
UnaExp::semantic(sc);
since the UnaExp::semantic() call turns the name into __overloadset which makes yucky error messages.