File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -922,6 +922,11 @@ def err_header_import_semi_in_macro : Error<
922
922
def err_header_import_not_header_unit : Error<
923
923
"header file %0 (aka '%1') cannot be imported because "
924
924
"it is not known to be a header unit">;
925
+ def warn_pp_include_angled_in_module_purview : Warning<
926
+ "'#include <filename>' attaches the declarations to the named module '%0'"
927
+ ", which is not usually intended; consider moving that directive before "
928
+ "the module declaration">,
929
+ InGroup<DiagGroup<"include-angled-in-module-purview">>;
925
930
926
931
def warn_header_guard : Warning<
927
932
"%0 is used as a header guard here, followed by #define of a different macro">,
Original file line number Diff line number Diff line change @@ -2537,6 +2537,10 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
2537
2537
return {ImportAction::None};
2538
2538
}
2539
2539
2540
+ if (isAngled && isInNamedModule ())
2541
+ Diag (FilenameTok, diag::warn_pp_include_angled_in_module_purview)
2542
+ << getNamedModuleName ();
2543
+
2540
2544
// Look up the file, create a File ID for it.
2541
2545
SourceLocation IncludePos = FilenameTok.getLocation ();
2542
2546
// If the filename string was the result of macro expansions, set the include
Original file line number Diff line number Diff line change
1
+ // RUN: rm -rf %t
2
+ // RUN: mkdir %t
3
+ // RUN: split-file %s %t
4
+ //
5
+ // RUN: %clang_cc1 -std=c++20 %t/a.cppm -E -P -I%t -o %t/tmp 2>&1 | FileCheck %t/a.cppm
6
+ // RUN: %clang_cc1 -std=c++20 %t/a.cppm -E -P -I%t -o - 2>&1 \
7
+ // RUN: -Wno-include-angled-in-module-purview | FileCheck %t/a.cppm --check-prefix=CHECK-NO-WARN
8
+
9
+ // --- a.h
10
+ // left empty
11
+
12
+ // --- b.h
13
+ #include < stddef.h>
14
+ // The headers not get included shouldn't be affected.
15
+ #ifdef WHATEVER
16
+ #include < stdint.h>
17
+ #endif
18
+
19
+ // --- a.cppm
20
+ module ;
21
+ #include < stddef.h>
22
+ #include < a.h>
23
+ #include < b.h>
24
+ #include " a.h"
25
+ #include " b.h"
26
+ export module a;
27
+
28
+ #include < stddef.h>
29
+ #include < a.h>
30
+ #include < b.h>
31
+ #include " a.h"
32
+ #include " b.h"
33
+
34
+ // CHECK: a.cppm:9:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
35
+ // CHECK: a.cppm:10:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
36
+ // CHECK: a.cppm:11:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
37
+ // CHECK: In file included from {{.*}}/a.cppm:11
38
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
39
+ // CHECK: In file included from {{.*}}/a.cppm:13
40
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
41
+
42
+ module :private;
43
+ #include < stddef.h>
44
+ #include < a.h>
45
+ #include < b.h>
46
+ #include " a.h"
47
+ #include " b.h"
48
+
49
+ // CHECK: a.cppm:24:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
50
+ // CHECK: a.cppm:25:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
51
+ // CHECK: a.cppm:26:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
52
+ // CHECK: In file included from {{.*}}/a.cppm:26
53
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
54
+ // CHECK: In file included from {{.*}}/a.cppm:28
55
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' attaches the declarations to the named module 'a'
56
+
57
+ // We should have catched all warnings.
58
+ // CHECK: 10 warnings generated.
59
+
60
+ // CHECK-NO-WARN-NOT: warning
You can’t perform that action at this time.
0 commit comments