<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125530>125530</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`-Winclude-angled-in-module-purview` false-positive
</td>
</tr>
<tr>
<th>Labels</th>
<td>
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vvd170501
</td>
</tr>
</table>
<pre>
`-Winclude-angled-in-module-purview` can be incorrectly diagnosed in the following case:
1. A header declares or defines a type named `module`.
2. The same header (or another one) declares a typedef for this type.
3. The header with typedef is included before an angled include.
```cpp
// test.h
struct module; // Doesn't trigger the warning, but needed for typedefs below
namespace ns {
struct module; // Same as above, type declaration doesn't trigger the warning
typedef module mod_alias1; // Also doesn't trigger the warning (typedef must be in global namespace?)
}
namespace {
// These typedefs also don't trigger the warning
typedef module mod_alias2;
typedef ns::module mod_alias3;
}
typedef module mod_alias4; // Triggers the warning in test.cpp
typedef ns::module mod_alias5; // Also triggers the warning
```
```cpp
// test.cpp
#include "test.h"
#include <iostream>
```
```bash
$ clang++-18 -c -std=c++20 test.cpp -c
test.cpp:2:10: warning: '#include <filename>' attaches the declarations to the named module 'mod_alias4', which is not usually intended; consider moving that directive before the module declaration [-Winclude-angled-in-module-purview]
2 | #include <iostream>
| ^
1 warning generated.
```
I couldn;t test a multi-file example with trunk clang, but the error can be also reproduced with a single file: https://godbolt.org/z/sdfb3bxPc
The single-file example is less realistic (includes are usually placed before any declarations or definitions), but could be easier to debug:
```cpp
struct module;
namespace ns {
struct module;
}
typedef module mod_alias4;
typedef ns::module mod_alias5;
#include <iostream>
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVl2P6jYQ_TXmZRTkOB8sDzyEpUh9q9SV-lhN7CFxa2xkO3C3v75yEliWvXfv6qJIIY5zZubMmZNgCLqzRBtWbVm1W-AQe-c357PKV7zi-aJ16nXDap79pa00g6IMbWdIZdpmR6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