[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / cxx20-hu-04.cpp
blob8546b33572dc83f282e0bc2febd6dc231bba56a1
1 // Test macro preservation in C++20 Header Units.
3 // RUN: rm -rf %t
4 // RUN: mkdir -p %t
5 // RUN: split-file %s %t
6 // RUN: cd %t
8 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
9 // RUN: -o hu-01.pcm
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
28 //--- hu-01.h
29 #ifndef __GUARD
30 #define __GUARD
32 int baz(int);
33 #define FORTYTWO 42
35 #define SHOULD_NOT_BE_DEFINED -1
36 #undef SHOULD_NOT_BE_DEFINED
38 #endif // __GUARD
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
44 //--- hu-02.h
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
48 #endif
50 #ifndef __GUARD
51 #error __GUARD missing in hu-02
52 #endif
54 #ifdef SHOULD_NOT_BE_DEFINED
55 #error SHOULD_NOT_BE_DEFINED is visible
56 #endif
58 #define KAP 6174
60 #ifdef FOO
61 #define FOO_BRANCH(X) (X) + 1
62 inline int foo(int x) {
63 if (x == FORTYTWO)
64 return FOO_BRANCH(x);
65 return FORTYTWO;
67 #else
68 #define BAR_BRANCH(X) (X) + 2
69 inline int bar(int x) {
70 if (x == FORTYTWO)
71 return BAR_BRANCH(x);
72 return FORTYTWO;
74 #endif
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
83 //--- importer-01.cpp
84 export module B;
85 import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
87 int success(int x) {
88 return foo(FORTYTWO + x + KAP);
91 int fail(int x) {
92 return bar(FORTYTWO + x + KAP); // expected-error {{use of undeclared identifier 'bar'}}
93 // expected-note@* {{'baz' declared here}}
96 //--- importer-02.cpp
97 export module C;
98 import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
100 int success(int x) {
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'