Skip to content

[clang] Polymorhic class templates are broken in modules #97313

Closed
@jasiolpn

Description

@jasiolpn

Hello,
Looks like I've found a new bug. I've compiled fresh LLVM (last commit ae570d8) and I tried to compile following files:

// Base.cppm
export module Mod:Base;

export template <class>
class Base
{
public:
    constexpr Base();
    constexpr virtual ~Base();
};

template <class X>
constexpr Base<X>::Base() = default;

template <class X>
constexpr Base<X>::~Base() = default;
// Sub.cppm
export module Mod:Sub;
import :Base;

export class Sub : public Base<int>
{
};
// Mod.cppm
export module Mod;
export import :Base;
export import :Sub;
// main.cpp
import Mod;

int main()
{
    Base<int> *b = new Sub();
    delete b;
}

Those files are compiled but the linker says:

/usr/bin/ld: CMakeFiles/vtable.dir/Sub.cppm.o:(.rodata+0xa): multiple definition of `typeinfo name for Base@Mod<int>'; CMakeFiles/vtable.dir/main.cpp.o:(.rodata+0x0): first defined here
/usr/bin/ld: CMakeFiles/vtable.dir/Sub.cppm.o:(.data.rel.ro+0x20): multiple definition of `typeinfo for Base@Mod<int>'; CMakeFiles/vtable.dir/main.cpp.o:(.data.rel.ro+0x20): first defined here

What is interesting is that if I make Base not to be template linker is doing its job successfully.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions