<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68615>68615</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] [Modules] Add warning for including header in module purview
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following code
```cpp
export module a;
#include <new>
```
When compiling with `-std=c++26 -stdlib=libc++ -Weverything`
all that we get as output is
```console
In file included from <source>:3:
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:217:66: error: declaration of 'operator new' in module a follows declaration in the global module
217 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:219:36: error: declaration of 'operator delete' in module a follows declaration in the global module
219 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:225:66: error: declaration of 'operator new[]' in module a follows declaration in the global module
225 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:227:36: error: declaration of 'operator delete[]' in module a follows declaration in the global module
227 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:234:66: error: declaration of 'operator new' in module a follows declaration in the global module
234 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:236:36: error: declaration of 'operator delete' in module a follows declaration in the global module
236 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:242:66: error: declaration of 'operator new[]' in module a follows declaration in the global module
242 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
| ^
note: previous declaration is here
/opt/compiler-explorer/clang-assertions-trunk-20231009/bin/../include/c++/v1/new:244:36: error: declaration of 'operator delete[]' in module a follows declaration in the global module
244 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
| ^
note: previous declaration is here
8 errors generated.
Compiler returned: 1
```
This is not obvious to users what they did wrong. The issue here is that the `#include` is in the module purview. It would be nice to have a general warning saying "Don't include there, type `module; #include <whatever>` instead.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWFtv2zgT_TX0y8CGRN2sBz_IF32fgWxTpNm2bwItjiXu0qRAUnbTX7-grLhNdrfYbbMJGsOwLN5mzpw5GoyYtaJRiAuSLEmynrDetdosODsKbp1WONlpfrf4nziiAtci7LWU-iRUA7XmSII1CYrxNw3O37rrziP4qdPGwUHzXiIwEi0frKeRULXsOQKJVgpPJNo8Ounr5R9aVFDrQyekt34SrgWSBlPrOInWNaFLQpc0BT8gxY5Eayl24zBMP-ARzZ1rhWoencukBNcyByeEBh0wC7p3Xe9A2L-Gp5XVcoS-VbAXEmFEwmFv9MHjsbo3NXpIURGR6IK51J0jtDwDQTPFT53UBo0fk0w1U2YtGie0slNn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