<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 - [C++20] [Module] The combination of iostream and file with .cppm suffix would crash"
   href="https://bugs.llvm.org/show_bug.cgi?id=52531">52531</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[C++20] [Module] The combination of iostream and file with .cppm suffix would crash
          </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>All
          </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>yedeng.yd@linux.alibaba.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>I met an interesting bug which would happen only if iosstream and module file
end with `.cppm`.
Here is the reproducer:
```C++
// Hello.cppm
module;
#include <iostream>
export module Hello;
export void SayHello()
{
    std::cout << "Hello World.\n";

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}

```

And if I compile it as:

```
clang++ -std=c++20 --precompile Hello.cppm -o Hello.pcm
clang++ -std=c++20 -fprebuilt-module-path=. Hello.pcm main.cpp
```

And the generated executable would crash.

Interestingly, it wouldn't crash if we use `std::printf` instead of `std::cout`

```C++
// Hello.cppm
module;
#include <cstdio>
export module Hello;
export void SayHello()
{
    std::printf("Hello World.\n");

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}
```

Also, it wouldn't crash if the suffix is `cpp` instead of `cppm`. For example:
```C++
// Hello.cpp
module;
#include <iostream>
export module Hello;
export void SayHello()
{
    std::cout << "Hello World.\n";

}
// main.cpp
import Hello;
int main() {
   SayHello();
   return 0;
}

```
Compile argument:
```
clang++ -std=c++20 -Xclang -emit-module-interface Hello.cpp -o Hello.pcm
clang++ -std=c++20 -fprebuilt-module-path=. say_hello.cpp main.cpp
```

I am not sure if this is a bug in compiler or in runtime. It is appreciate if
someone could help to confirm this.</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>