File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -922,6 +922,10 @@ 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>' in the module purview appears to be erroneous; "
927
+ "consider moving that directive before the module declaration">,
928
+ InGroup<DiagGroup<"include-angled-in-module-purview">>;
925
929
926
930
def warn_header_guard : Warning<
927
931
"%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 @@ -2530,6 +2530,9 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
2530
2530
return {ImportAction::None};
2531
2531
}
2532
2532
2533
+ if (isAngled && isInNamedModule ())
2534
+ Diag (FilenameTok, diag::warn_pp_include_angled_in_module_purview);
2535
+
2533
2536
// Look up the file, create a File ID for it.
2534
2537
SourceLocation IncludePos = FilenameTok.getLocation ();
2535
2538
// 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>' in the module purview appears to be erroneous;
35
+ // CHECK: a.cppm:10:10: warning: '#include <filename>' in the module purview appears to be erroneous;
36
+ // CHECK: a.cppm:11:10: warning: '#include <filename>' in the module purview appears to be erroneous;
37
+ // CHECK: In file included from {{.*}}/a.cppm:11
38
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' in the module purview appears to be erroneous;
39
+ // CHECK: In file included from {{.*}}/a.cppm:13
40
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' in the module purview appears to be erroneous;
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>' in the module purview appears to be erroneous;
50
+ // CHECK: a.cppm:25:10: warning: '#include <filename>' in the module purview appears to be erroneous;
51
+ // CHECK: a.cppm:26:10: warning: '#include <filename>' in the module purview appears to be erroneous;
52
+ // CHECK: In file included from {{.*}}/a.cppm:26
53
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' in the module purview appears to be erroneous;
54
+ // CHECK: In file included from {{.*}}/a.cppm:28
55
+ // CHECK-NEXT: b.h:1:10: warning: '#include <filename>' in the module purview appears to be erroneous;
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