www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Class inheritance bug

reply "Tobias M." <tobias.m onlinehome.de> writes:
Hi,
i first had this bug:
-------main.d-------
import std.socket;
class Foo : Address {
}
void main() {
}
-------END-------
that lead to several undefined symbols when linking.


But now i have this:
-------main.d-------
import core.thread;
class Foo : Thread {
}
void main() {
}
-------END-------
And i get an undefined symbol, again.

-------Compiler output-------
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
dist\client.obj(client)
  Error 42: Symbol Undefined _D14ListenerThread12__ModuleInfoZ
--- errorlevel 1
-------END-------

I am running Windows7 32bit, DMD 2.056

So this is clearly a bug in my eyes, any opinions about that?
Nov 10 2011
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 11/11/11, Tobias M. <tobias.m onlinehome.de> wrote:
 Hi,
 i first had this bug:
 -------main.d-------
 import std.socket;
 class Foo : Address {
 }
 void main() {
 }
 -------END-------
 that lead to several undefined symbols when linking.
I can recreate this.
 But now i have this:
 -------main.d-------
 import core.thread;
 class Foo : Thread {
 }
 void main() {
 }
 -------END-------
 And i get an undefined symbol, again.
That shouldn't even compile. I need to call Thread's ctor, otherwise I get: Error: constructor test.Foo.this no match for implicit super() call in constructor This compiles fine though: class Foo : Thread { this() { super( &run ); } void run() {} }
Nov 10 2011
prev sibling next sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
 From what I see, it looks like the linked did not do its job. :)
Nov 10 2011
prev sibling next sibling parent reply mta`chrono <chrono mta-international.net> writes:
Hi Tobias,

in your last post you'd asked something about sockets and now you're
asking about threads which leads me to say: You don't need threads to
use thousands of sockets at the same time. There is Socket.select which
is some kind of multiplexer doing all the nasty shit for observating
multiple sockets. If you really wanna use threads, then please note: you
don't need to subclass it. you can of course but it also accepts a
delegate or a function in it's constructor.

----
import core.thread;

void foobar()
{

}

void main();
{
    Thread thread = new core.thread(&foobar);
    thread.start();
}
----
Nov 11 2011
parent reply Tobias M. <tobias.m onlinehome.de> writes:
I did not want to use threads for mutile sockets. I wanted to have the main
thread
prompting the user for input with readln() and a new thread listening for
incoming
messages and printing them with writeln(). But ill have to see if that actually
works.


compile

subclasses. This has to be fixed.
In the cases where a class does not need to be extended it could be declared as
final but that would be out-of-scope and topic.
Nov 11 2011
next sibling parent mta`chrono <chrono mta-international.net> writes:
Dont understand me wrong. You can subclass it OR you can use it like it
is. Two possibilies to use. Use the one that suits your needs. By the
way, there is a newsgroup called D.learn which I think is a better place
for your questions.

- mta`chrono

---- Example 1 ----
import std.stdio;
import core.thread;

class MyOwnThread : Thread
{
        public this()
        {
            super(&run);
        }

        private void run()
        {
            writeln("I'm a new Thread");
        }
}

void main()
{
    MyOwnThread thread = new MyOwnThread();
    thread.start();
}
----


---- Example 2 ----
import std.stdio;
import core.thread;

void foobar()
{
    writeln("I'm a new Thread");
}

void main();
{
    Thread thread = new core.thread(&foobar);
    thread.start();
}
----
Nov 11 2011
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 11/11/2011 11:00 AM, Tobias M. wrote:
 I did not want to use threads for mutile sockets. I wanted to have the main
thread
 prompting the user for input with readln() and a new thread listening for
incoming
 messages and printing them with writeln(). But ill have to see if that
actually works.

 The problem here is not Threads but that whenever i extend a class i


 subclasses. This has to be fixed.
It is not some kind of extreme showstopper bug that somehow nobody else noticed, it is some specific issue you have with the toolchain. Your code import core.thread; class Foo : Thread { } void main() { } Does not compile on my machine, it fails with Error: constructor A.Foo.this no match for implicit super() call in constructor So 1. What version of DMD are you using and on what architecture/OS? 2. What is the actual code that gives a linker error? 3. How do you compile it?
Nov 11 2011
parent reply "Tobias M." <tobias.m onlinehome.de> writes:
No, this is seriously a bug. I tried around to get it linked correctly 
but kept failing. So then i tried to find a general example and here it is:
---------test.d---------
module test;
abstract class Foobar {
	this(string arg) {
		// do sth.
	}
}
class Blub : Foobar {
	this(string arg) {
		super(arg);
		// do sth.
	}
}
---------END---------
Compiling on Windows7(32bit) SP1 with DMD 2.056 (for some reason) using 
phobos 2.055:
---------command prompt---------
C:\Users\Tobse\Documents\chat>dmd test.d
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 23: No Stack
test.obj(test)
  Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ
test.obj(test)
  Error 42: Symbol Undefined _D6Object7__ClassZ
test.obj(test)
  Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectC6ObjectZb
test.obj(test)
  Error 42: Symbol Undefined _D6object6Object6toHashMFZk
test.obj(test)
  Error 42: Symbol Undefined _D6object6Object8toStringMFZAya
test.obj(test)
  Error 42: Symbol Undefined _D6object6Object5opCmpMFC6ObjectZi
test.obj(test)
  Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectZb
OPTLINK : Warning 134: No Start Address
--- errorlevel 7
---------END---------

while this compiles, links and runs perfectly:
---------test.d---------
module test;
abstract class Foobar {
	this(string arg) {
		// do sth.
	}
}
class Blub : Foobar {
	this(string arg) {
		super(arg);
		// do sth.
	}
}

void main() {
	// do sth.
}
---------END---------

---------command prompt---------
C:\Users\Tobse\Documents\chat>dmd test.d

C:\Users\Tobse\Documents\chat>test
Hello World!
---------END---------


So i could implement the functions toHash, toString, opCmpMF and 
opEquals (as these symbols are undefined), but thats not the way the 
language reference on d-programming-language.org documents class 
inheritance.
Finally, from my point of view, this is a bug.
Nov 11 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 11 Nov 2011 15:28:41 -0500, Tobias M. <tobias.m onlinehome.de>  
wrote:

 No, this is seriously a bug. I tried around to get it linked correctly  
 but kept failing. So then i tried to find a general example and here it  
 is:
 ---------test.d---------
 module test;
 abstract class Foobar {
 	this(string arg) {
 		// do sth.
 	}
 }
 class Blub : Foobar {
 	this(string arg) {
 		super(arg);
 		// do sth.
 	}
 }
 ---------END---------
 Compiling on Windows7(32bit) SP1 with DMD 2.056 (for some reason) using  
 phobos 2.055:
 ---------command prompt---------
 C:\Users\Tobse\Documents\chat>dmd test.d
 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 OPTLINK : Warning 23: No Stack
 test.obj(test)
   Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ
 test.obj(test)
   Error 42: Symbol Undefined _D6Object7__ClassZ
 test.obj(test)
   Error 42: Symbol Undefined  
 _D6object6Object8opEqualsMFC6ObjectC6ObjectZb
 test.obj(test)
   Error 42: Symbol Undefined _D6object6Object6toHashMFZk
 test.obj(test)
   Error 42: Symbol Undefined _D6object6Object8toStringMFZAya
 test.obj(test)
   Error 42: Symbol Undefined _D6object6Object5opCmpMFC6ObjectZi
 test.obj(test)
   Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectZb
 OPTLINK : Warning 134: No Start Address
 --- errorlevel 7
 ---------END---------
This does not link because there is no main function. main() is required to link. Note the "Warning 134: No Start Address" message -Steve
Nov 11 2011
parent reply "Tobias M." <tobias.m onlinehome.de> writes:
 This does not link because there is no main function. main() is required
 to link.

 Note the "Warning 134: No Start Address" message

 -Steve
Why has the lack of a main funcktion (or start address) something to do with unimplemented methods?
Nov 11 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Because optlink works in mysterious ways. :p Generally I've found the
best thing to do is ignore optlink error messages and try figuring out
where my build process went wrong, the linker error messages can be
misleading.
Nov 11 2011
parent "Tobias M." <tobias.m onlinehome.de> writes:
Am 12.11.2011 01:16, schrieb Andrej Mitrovic:
 Because optlink works in mysterious ways. [...]the linker error messages can be
 misleading.
Thats what it seems to be ;). Great THANKS to all of you!
Nov 12 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 11 Nov 2011 17:51:38 -0500, Tobias M. <tobias.m onlinehome.de>  
wrote:

 This does not link because there is no main function. main() is required
 to link.

 Note the "Warning 134: No Start Address" message

 -Steve
Why has the lack of a main funcktion (or start address) something to do with unimplemented methods?
There are no unimplemented methods. They just aren't being linked in. All is fixed with a main method. If you wish to compile code without linking, you can do it via dmd -c. Then you will not get linker errors without a main method. General rule of thumb -- if you are getting linker errors, most likely the issue is with your build (i.e. you aren't passing enough stuff on the command line, or in the right order). The one exception is the main function, which is always expected by the linker, and must be provided by you (it's not in any library). -Steve
Nov 14 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 10 Nov 2011 18:45:56 -0500, Tobias M. <tobias.m onlinehome.de>  
wrote:

 Hi,
 i first had this bug:
 -------main.d-------
 import std.socket;
 class Foo : Address {
 }
 void main() {
 }
 -------END-------
 that lead to several undefined symbols when linking.
This is a bug in the compiler or phobos. It fails to link on Linux as well.
 But now i have this:
 -------main.d-------
 import core.thread;
 class Foo : Thread {
 }
 void main() {
 }
 -------END-------
 And i get an undefined symbol, again.

 -------Compiler output-------
 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
   Error 42: Symbol Undefined _D14ListenerThread12__ModuleInfoZ
 --- errorlevel 1
 -------END-------
This *appears* like you imported some module (named ListenerThread?) but did not include it on the compile line. Clearly the above code is not what produced this error. Please post reduced code that generates a similar error, or post the original code. -Steve
Nov 11 2011