1 // Test macro preservation in C++20 Header Units.
5 // RUN: split-file %s %t
8 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
11 // RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
12 // RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
14 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
15 // RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm -Rmodule-import 2>&1 | \
16 // RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
18 // RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \
19 // RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t
21 // RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-01.cpp \
22 // RUN: -fmodule-file=hu-02.pcm -o B.pcm -verify
24 // RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-02.cpp \
25 // RUN: -fmodule-file=hu-02.pcm -o C.pcm -Rmodule-import 2>&1 | \
26 // RUN: FileCheck --check-prefix=CHECK-IMP-HU2 %s -DTDIR=%t
35 #define SHOULD_NOT_BE_DEFINED -1
36 #undef SHOULD_NOT_BE_DEFINED
39 // expected-no-diagnostics
41 // CHECK-HU: ====== C++20 Module structure ======
42 // CHECK-HU-NEXT: Header Unit '.{{/|\\\\?}}hu-01.h' is the Primary Module at index #1
45 export import
"hu-01.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
46 #if !defined(FORTYTWO) || FORTYTWO != 42
47 #error FORTYTWO missing in hu-02
51 #error __GUARD missing in hu-02
54 #ifdef SHOULD_NOT_BE_DEFINED
55 #error SHOULD_NOT_BE_DEFINED is visible
61 #define FOO_BRANCH(X) (X) + 1
62 inline int foo(int x
) {
68 #define BAR_BRANCH(X) (X) + 2
69 inline int bar(int x
) {
76 // CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm'
77 // CHECK-HU2: ====== C++20 Module structure ======
78 // CHECK-HU2-NEXT: Header Unit '.{{/|\\\\?}}hu-02.h' is the Primary Module at index #2
79 // CHECK-HU2-NEXT: Exports:
80 // CHECK-HU2-NEXT: Header Unit '.{{/|\\\\?}}hu-01.h' is at index #1
81 // expected-no-diagnostics
85 import
"hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
88 return foo(FORTYTWO
+ x
+ KAP
);
92 return bar(FORTYTWO
+ x
+ KAP
); // expected-error {{use of undeclared identifier 'bar'}}
93 // expected-note@* {{'baz' declared here}}
98 import
"hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
101 return foo(FORTYTWO
+ x
+ KAP
);
104 // CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-02.h' from 'hu-02.pcm'
105 // CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-01.h' into '.{{/|\\\\?}}hu-02.h' from '[[TDIR]]{{[/\\]}}hu-01.pcm'