<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Undefined symbol when using iostream in module interface unit"
   href="https://bugs.llvm.org/show_bug.cgi?id=51910">51910</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Undefined symbol when using iostream in module interface unit
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++2a
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>is7e9jnxv@protonmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25273" name="attach_25273" title="test case">attachment 25273</a> <a href="attachment.cgi?id=25273&action=edit" title="test case">[details]</a></span>
test case

On x86-64 Ubuntu 21.04, when I use cout and endl together in a function defined
in a module interface unit, the linker (both ld and lld) reports that that
function is not defined, but only when there is also a corresponding module
implementation unit. Reference the following compile commands with the attached
file containing the text of the three source files clangbug.cpp, clangbug.cppm,
and main.cpp. Removing endl from the line causing the linker failure (line 2 of
somethingElse()) also resolves the issue. Omitting -flto does not affect the
outcome.

clang++ -fmodules -std=c++20 -stdlib=libc++ -Wall -Wextra -Wpedantic -O3 -flto
--precompile -o clangbug.pcm clangbug.cppm

clang++ -fmodules -std=c++20 -stdlib=libc++ -Wall -Wextra -Wpedantic -O3 -flto
clangbug.pcm clangbug.cpp -fmodule-file=clangbug.pcm -c

clang++ --ld-path=ld.lld -fmodules -std=c++20 -stdlib=libc++ -Wall -Wextra
-Wpedantic -O3 -flto -o clangbugTest clangbug.o main.cpp
-fmodule-file=clangbug.pcm

ld.lld: error: undefined symbol: _ZW8clangbugE13somethingElsev
<span class="quote">>>> referenced by ld-temp.o
>>>               lto.tmp:(main)</span >
clang-14: error: linker command failed with exit code 1 (use -v to see
invocation)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>