<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58560>58560</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang++-16: Linking error when importing virtual classes.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mls-m5
      </td>
    </tr>
</table>

<pre>
    I get a linker error when trying to import and inherit from a virtual class.

A minimal test case. (Could be smaller if the std-lib stuff is removed)

```c++
// base.cppm
export module base;

export struct Base {
    virtual void hello() = 0;
    virtual ~Base() = default;
};
```

```c++
// derived.cppm

export module derived;

import <iostream>;
export import base;

export class Derived : public Base {
public:
    void hello() override {
        std::cout << "hello from derived\n";
    }
};

```

```c++
// main
import derived;
import <memory>;
import <iostream>;

int main(int argc, char *argv[]) {
    // This does not seem to link properly
    auto derived = std::make_shared<Derived>();
    std::cout << "hello from main" << std::endl;
    derived->hello();

    Base &b = *derived;
    b.hello();

    return 0;
}
```

Building with
```bash
clang++-16 -std=c++20 -stdlib=libc++ "base.cppm"  -MD -MF "base.pcm.d"  --precompile -o  "base.pcm"
clang++-16 -std=c++20 -stdlib=libc++ "base.pcm"   -c -o  "base.o" 
clang++-16 -std=c++20 -stdlib=libc++ -xc++-system-header --precompile memory  -o  "memory.pcm" 
clang++-16 -std=c++20 -stdlib=libc++ -xc++-system-header --precompile iostream  -o  "iostream.pcm"
clang++-16 -std=c++20 -stdlib=libc++ "derived.cppm"  -fmodule-file="iostream.pcm" -fmodule-file="base.pcm" -MD -MF "derived.pcm.d"  --precompile -o  "derived.pcm" 
clang++-16 -std=c++20 -stdlib=libc++ "derived.pcm"   -c -o  "derived.o" 
clang++-16 -std=c++20 -stdlib=libc++ "main.cpp"  -fmodule-file="derived.pcm" -fmodule-file="memory.pcm" -fmodule-file="iostream.pcm"  -c -o  "main.o" 
clang++-16 -std=c++20 -stdlib=libc++   "base.o" "derived.o" "main.o"  -o  "build/default/main" 
```

Get linker error like

```bash
/usr/bin/ld: main.o: in function `_ZNSt3__120__shared_ptr_emplaceIW7derived7DerivedNS_9allocatorIS2_EEED0Ev':
main.cpp:(.text._ZNSt3__120__shared_ptr_emplaceIW7derived7DerivedNS_9allocatorIS2_EEED0Ev[_ZNSt3__120__shared_ptr_emplaceIW7derived7DerivedNS_9allocatorIS2_EEED0Ev]+0x1e): undefined reference to `_ZW4basedlPv'
/usr/bin/ld: main.o: in function `_ZNW7derived7DerivedD0Ev':
main.cpp:(.text._ZNW7derived7DerivedD0Ev[_ZNW7derived7DerivedD0Ev]+0x1e): undefined reference to `_ZW4basedlPv'
/usr/bin/ld: main.o: in function `void std::__1::__libcpp_operator_delete[abi:v160000]<void*>(void*)':
main.cpp:(.text._ZNSt3__124__libcpp_operator_deleteB7v160000IJPvEEEvDpT_[_ZNSt3__124__libcpp_operator_deleteB7v160000IJPvEEEvDpT_]+0x11): undefined reference to `_ZW4basedlPv'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

It is possible to create include-file of the `base` class, but for my real example that solutino would not work.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9V1tvqzgQ_jXkxSIiECB9yENuXXW1e3Skc6Qj7QsCPAneGoyMSdN_v2MbEkjTqtt2NyJc7PFcvrl4nAn6vHwgB1AkJZxVjyAJSCkkeSqgIko-s-pAlCCsrIVEoooSVhUgmSJ7KUpcdWRStSknOU-bZup4W8db2fuKlKxiJc4paBTJ0wamxPEXG9FySjIgDc5xlMj2RBX4qajLWYbPdr8nrCESSnEE6vh3Q7ZO5Nkrd_y1vuyof48XybSQvK5LOwono3YpaMvBTDrBesisI2iUbHNF1khAnLijIPjrrTsKRkkBnAs0ABUiTrAl3pnZkNSJd5rPgI7CPm25uoiOt5f33pp3m0gRfURlYOUtWzuqK3M7NzrBhgm0GdLSCXZnmo5DR_Q6WsbVZGslILMVqduMs_wKP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