Bug 8599 – Link time error when class's method are defined without body and nothing is abstract

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-29T12:52:00Z
Last change time
2012-09-02T12:55:53Z
Assigned to
nobody
Creator
deadalnix

Comments

Comment #0 by deadalnix — 2012-08-29T12:52:57Z
The sample code is the simplest ever : class A { void foo(); } This will cause the error : classfail.o:(.rodata+0x50): undefined reference to `_D9classfail1A3fooMFZv' when compiling with dmd 2.060 declaring A or foo as abstract fix the problem. abstract should be deducted from code or compilation should fail before linking stage.
Comment #1 by issues.dlang — 2012-08-29T14:00:34Z
abstract is never inferred. Why would it be inferred? Functions are only abstract if marked abstract. And if a function is not abstract, then it needs a body/definition, so obviousy it's going to fail at link time when the linker doesn't find a definition for it. It's perfectly legal to declare a function without giving its body as long as the linker has the body. That's how .di files work. It's also useful with stuff like version(D_Ddoc) where there is no definition and shouldn't be one. This isn't a bug.
Comment #2 by deadalnix — 2012-09-02T12:55:53Z
(In reply to comment #1) > abstract is never inferred. Why would it be inferred? Functions are only > abstract if marked abstract. > > And if a function is not abstract, then it needs a body/definition, so obviousy > it's going to fail at link time when the linker doesn't find a definition for > it. It's perfectly legal to declare a function without giving its body as long > as the linker has the body. That's how .di files work. It's also useful with > stuff like version(D_Ddoc) where there is no definition and shouldn't be one. > > This isn't a bug. You are right. I'm so dumb sometime.