<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77995>77995</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[c++20][modules] '#pragma once' doesn't work with files included in global module fragment
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jdrouhard
</td>
</tr>
</table>
<pre>
This isn't quite the same reproducer as #38554 or #58532 and the issue still exists in 17.0.6.
When using `#pragma once`, included files in the global module fragment hide the visibility of everything declared in them when the module is imported before a normal `#include`. This error disappears (and the example works) if _either_ the `#pragma once`s are turned into normal include guards, _or_ the `import c;` and `#include "a.hpp"` are swapped in the importing translation unit (d.cpp).
```cpp
// a.hpp
#pragma once
using a = int;
```
```cpp
// b.hpp
#pragma once
a b;
```
```cpp
// c.cpp
module;
#include "b.hpp"
export module c;
export using foo = a;
```
```
// d.cpp
import c;
#include "a.hpp"
a d;
foo f;
```
compile with:
```
clang++ -std=c++20 -x c++-module -fmodule-output=c.pcm -o c.o -c ./c.cpp
clang++ -std=c++20 -fmodule-file=c=c.pcm -c -o d.o d.cpp
```
error:
```
d.cpp:4:1: error: missing '#include "a.hpp"'; 'a' must be declared before it is used
4 | a d;
| ^
/.../a.hpp:2:7: note: declaration here is not visible
2 | using a = int;
| ^
1 error generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVd2OszgMfZpwYxWlSYFywUX7dfsEK-3lKBAX8m1I2CTMz9uvEujfamY02tGogJMcHx87tvBe9QaxIcWRFKdMzGGwrvktnZ0H4WTWWvnR_DkoD8obwqoA_8wqIIQBwYsRweHkrJw7dCA8EMb5vih2YF18L_YFZyCMTPuV9zOCD0prwHflgwdlYFvlNC9zQk-EHpbfvwY0MHtleiAlJYxPTvSjAGs6TIZfoEynZ4kSLkpjwokeem1boWG0ctYIl3gKTYBByYXxq_KqVVqFD7A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