[Issue 866] New: Abstract classes can't have constructors: fails to link, hard to find problem

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 21 04:10:36 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=866

           Summary: Abstract classes can't have constructors: fails to link,
                    hard to find problem
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic, link-failure, spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: deewiant at gmail.com


abstract class Parent {
        this();
}

class Child : Parent {
        override this() {}
}

void main() {
        // both fail to link
        Parent p = new Child;
        Child c = new Child;
}

The above code fails to link, emitting "Symbol Undefined" errors referring to
Parent._ctor. This ought to be caught by the compiler, as it's quite difficult
to find the problem when you don't know what you're looking for.

The override attribute of the constructor in Child is completely ignored: if
Parent's constructor is removed, the code compiles and runs. I know that DMD
ignores superfluous attributes, but this might be a good case to tag it as a n

The fact that abstract classes can't have constructors is unmentioned in the
spec (at least in attribute.html, where I would expect it to be stated), which
is why I tagged this with "spec".

Changing Parent to the following:

class Parent {
        abstract this();
}

The error "constructor asdf.Parent.this non-virtual functions cannot be
abstract" is emitted.

Changing Parent to an interface causes the error "constructor asdf.Parent.this
special function not allowed in interface Parent", which is the kind of error I
would expect for the abstract class as well.

My ideal error messages would read:

"interface cannot contain non-virtual function asdf.Parent.this"
"abstract class cannot contain non-virtual function asdf.Parent.this"
"non-virtual function asdf.Parent.this cannot be abstract"


-- 



More information about the Digitalmars-d-bugs mailing list