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

    <tr>
        <th>Summary</th>
        <td>
            [C++20][Modules] Multiple definitions of v-table
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          DanielaE
      </td>
    </tr>
</table>

<pre>
    During my efforts of making [my module test suite of the {fmt} library](https://github.com/DanielaE/fmt/tree/test-with-modules) compile with Clang 16.0 I ran into this issue. I have stripped it down as much as I can, the [result is here on CE](https://godbolt.org/z/jTK71s8fY).

Building it manually like so
```
clang++ -std=c++20 -O1 -DNDEBUG -fmodule-output -c fmt.cppm
clang++ -std=c++20 -O1 -DNDEBUG -fprebuilt-module-path=. fmt.pcm main.cpp os.cpp
```
I get

```
E:/msys64/bin/ld: E:/msys64/tmp/main.o:main.cpp:(.rdata+0x0):
 multiple definition of `vtable for fmt::detail::file_buffer@fmt';
 E:/msys64/tmp/fm.o:fmt.pcm:(.rdata+0x0): first defined here
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
The compiler seems to place a 2nd copy of the v-table of non-exported `class file_buffer final : public buffer<char>` with non-exported polymorphic base `template<typename T> class buffer` into the object files. That class `file_buffer` is a member of exported `class ostream`.

Compiling `os.cpp` in the second line (above) is _not_ necessary to trigger the issue. It's just a further complication because it emits a _different_ v-table of the same classes, but this time attached to the global module rather than module fmt.

Compilation succeeds if optimization is disabled by `-O0`. ðŸŽ‰

(Only for reference: MSVC is compiling this example and mentioned test suite just fine.)

[repro.zip](https://github.com/llvm/llvm-project/files/11361505/repro.zip)

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