Skip to content

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

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

Closed
jasiolpn opened this issue Jul 1, 2024 · 1 comment
Closed

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

jasiolpn opened this issue Jul 1, 2024 · 1 comment
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@jasiolpn
Copy link

jasiolpn commented Jul 1, 2024

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.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jul 1, 2024
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed clang Clang issues not falling into any other category labels Jul 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2024

@llvm/issue-subscribers-clang-modules

Author: Marcin Nowak (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 &lt;class&gt;
class Base
{
public:
    constexpr Base();
    constexpr virtual ~Base();
};

template &lt;class X&gt;
constexpr Base&lt;X&gt;::Base() = default;

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

export class Sub : public Base&lt;int&gt;
{
};
// Mod.cppm
export module Mod;
export import :Base;
export import :Sub;
// main.cpp
import Mod;

int main()
{
    Base&lt;int&gt; *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&lt;int&gt;'; 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&lt;int&gt;'; 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.

@ChuanqiXu9 ChuanqiXu9 self-assigned this Jul 2, 2024
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this issue Jul 3, 2024
named modules

Close llvm#97313

In the previous patch (llvm#75912),
I made an oversight that I ignored the templates in named module when
calculating the linkage for the vtables. In this patch, I tried to
correct the behavior by merging the logics to calculate the linkage with
key functions with named modules.
kbluck pushed a commit to kbluck/llvm-project that referenced this issue Jul 6, 2024
named modules

Close llvm#97313

In the previous patch (llvm#75912),
I made an oversight that I ignored the templates in named module when
calculating the linkage for the vtables. In this patch, I tried to
correct the behavior by merging the logics to calculate the linkage with
key functions with named modules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

4 participants