Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate definition for deleting destructor #318

Closed
jayrm opened this issue Jun 13, 2021 · 1 comment
Closed

Duplicate definition for deleting destructor #318

jayrm opened this issue Jun 13, 2021 · 1 comment

Comments

@jayrm
Copy link
Member

jayrm commented Jun 13, 2021

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

@jayrm
Copy link
Member Author

jayrm commented Jun 16, 2021

fixed in fbc 1.08.1 in [bce19e9]
merged in to fbc 1.09.0 in [abc89c3]

@jayrm jayrm closed this as completed Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant