D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3119 - Segfault(expression.c) template function overloads with function with same name in other module
Summary: Segfault(expression.c) template function overloads with function with same na...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2009-06-30 23:40 UTC by Jesse Phillips
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jesse Phillips 2009-06-30 23:40:15 UTC
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 Don 2009-10-08 05:09:51 UTC
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 Don 2009-10-09 05:23:42 UTC
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 Don 2009-10-09 07:36:36 UTC
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.
Comment 4 Walter Bright 2009-10-13 13:52:17 UTC
Fixed dmd 2.034