Issue |
125530
|
Summary |
`-Winclude-angled-in-module-purview` false-positive
|
Labels |
false-positive
|
Assignees |
|
Reporter |
vvd170501
|
`-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>
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs