Skip to content

Duplicate definition for deleting destructor #318

@jayrm

Description

@jayrm

In the fbc-1.08.0 release there were improvements for setting up the virtual table to include the deleting destructor.
This created a new bug where fbc is emitting the deleting destructor even though the class is declared only on the fbc side.

Resulting in the following (or similar):

ld: class.o: in function `base::~base()':
class.cpp:(.text+0x94): multiple definition of `base::~base()'; test.o:test.c:(.text+0x0): first defined here
ld: class.o: in function `derived::~derived()':
class.cpp:(.text+0x20c): multiple definition of `derived::~derived()'; test.o:test.c:(.text+0x52): first defined here

Example:
class.cpp

#include <iostream>
using namespace std;
 
class base {
public:
base();
virtual ~base();
    virtual void print() ;
    virtual void show() ;
};
 
class derived : public base {
public:
derived();
virtual ~derived();
    void print() ;
    void show() ;
};

base::base(){
cout << "base constructor" << endl;
}

base::~base(){
cout << "base destructor" << endl;
}

void base::print()
   {
        cout << "print base class" << endl;
    }
 
    void base::show()
    {
        cout << "show base class" << endl;
    }

derived::derived(){
cout << "derived constructor" << endl;
}

derived::~derived(){
cout << "derived destructor" << endl;
}

    void derived::print()
    {
        cout << "print derived class" << endl;
    }
 
    void derived::show()
    {
        cout << "show derived class" << endl;
    } 

test.bas

#undef base

extern "c++"
type base extends object
   declare constructor
   declare virtual destructor
   declare virtual sub print()
   declare virtual sub show
end type

type derived extends base
   declare constructor
   declare virtual destructor
   declare sub print()
   declare sub show
end type

end extern


dim z as base ptr=new derived

'z->print
z->show

Forum post: https://www.freebasic.net/forum/viewtopic.php?p=283373#p283373
Example code: https://www.freebasic.net/forum/viewtopic.php?p=272431#p272431

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions