[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/105442] New: [modules] exporting a class with an inline virtual destructor causes linker er
From:       "john at johnmaddock dot co.uk via Gcc-bugs" <gcc-bugs () gcc ! gnu ! org>
Date:       2022-04-30 17:22:34
Message-ID: bug-105442-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105442

            Bug ID: 105442
           Summary: [modules] exporting a class with an inline virtual
                    destructor causes linker errors (duplicate symbols)
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john at johnmaddock dot co.uk
  Target Milestone: ---

Found while experimenting with modules for Boost.Math, consider a module which
exports an exception type:

module;

#include <stdexcept>

export module virtual_destructor_test;

export class evaluation_error : public std::runtime_error
{
public:
   evaluation_error(const std::string& s) : std::runtime_error(s) {}
   inline ~evaluation_error() {}
};

And a trivial program which uses it:

#include <string>

import virtual_destructor_test;

int main()
{
   evaluation_error eval(std::string("test me"));
}

Then I see:

D:/compilers/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:\compilers\msys64\tmp\cch2gAHF.o:virtual_test.c:(.text+0x0): multiple
definition of `evaluation_error::~evaluation_error()';
D:\compilers\msys64\tmp\cc35c6Fy.o:virtual.cxx:(.text$_ZN16evaluation_errorD1Ev[_ZN16evaluation_errorD1Ev]+0x0):
 first defined here
D:/compilers/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:\compilers\msys64\tmp\cch2gAHF.o:virtual_test.c:(.text+0x2e): multiple
definition of `evaluation_error::~evaluation_error()';
D:\compilers\msys64\tmp\cc35c6Fy.o:virtual.cxx:(.text$_ZN16evaluation_errorD0Ev[_ZN16evaluation_errorD0Ev]+0x0):
 first defined here
D:/compilers/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:\compilers\msys64\tmp\cch2gAHF.o:virtual_test.c:(.rdata+0x50): multiple
definition of `vtable for evaluation_error';
D:\compilers\msys64\tmp\cc35c6Fy.o:virtual.cxx:(.rdata$_ZTV16evaluation_error[_ZTV16evaluation_error]+0x0):
 first defined here

The issue occurs if:

* No destructor is declared.
* The destructor is = default;
* The destructor is inline.

It does NOT occur if the destructor is declared non-inline.

Looks like the compiler should assume that vtables are always in the module?=


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic