www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21416] New: betterC mode program with C++ interface fails to


          Issue ID: 21416
           Summary: betterC mode program with C++ interface fails to link
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mobile majumdar.org.uk

import core.stdc.stdio : printf;

//extern (C++) abstract class A {
extern (C++) interface A {
    void sayHello();

extern (C++) class B : A {
    override void sayHello() {

extern (C) void main() {
    scope b = new B;

Above fails to link with DMD, works with LDC.

~/Software/dmd2/linux/bin64/dmd -betterC interfaces.d 
interfaces.o:(.data._D10interfaces1A11__InterfaceZ+0x0): undefined reference to
interfaces.o:(.data._D10interfaces1B6__initZ+0x8): undefined reference to
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Tested on RHEL 7.9
DMD64 D Compiler v2.094.1

Replacing 'interface' with 'abstract class' appears to work in DMD, but this
should not be necessary since interface is extern (C++).

Nov 22 2020