[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / cxx20-hu-06.cpp
blobccbae155e8d6dc44f6909a4ceaad24452c938597
1 // Test check that consuming -E -fdirectives-only output produces the expected
2 // header unit.
4 // RUN: rm -rf %t
5 // RUN: mkdir -p %t
6 // RUN: split-file %s %t
7 // RUN: cd %t
9 // RUN: %clang_cc1 -std=c++20 -E -fdirectives-only -xc++-user-header hu-01.h \
10 // RUN: -o hu-01.iih
12 // RUN: %clang_cc1 -std=c++20 -emit-header-unit \
13 // RUN: -xc++-user-header-cpp-output hu-01.iih -o hu-01.pcm
15 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
16 // RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm -Rmodule-import 2>&1 | \
17 // RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
19 //--- hu-01.h
20 #ifndef __GUARD
21 #define __GUARD
23 int baz(int);
24 #define FORTYTWO 42
26 #define SHOULD_NOT_BE_DEFINED -1
27 #undef SHOULD_NOT_BE_DEFINED
29 #endif // __GUARD
30 // expected-no-diagnostics
32 //--- hu-02.h
33 export import "hu-01.h";
34 #if !defined(FORTYTWO) || FORTYTWO != 42
35 #error FORTYTWO missing in hu-02
36 #endif
38 #ifndef __GUARD
39 #error __GUARD missing in hu-02
40 #endif
42 #ifdef SHOULD_NOT_BE_DEFINED
43 #error SHOULD_NOT_BE_DEFINED is visible
44 #endif
46 // Make sure that we have not discarded macros from the builtin file.
47 #ifndef __cplusplus
48 #error we dropped a defined macro
49 #endif
51 #define KAP 6174
53 #ifdef FOO
54 #define FOO_BRANCH(X) (X) + 1
55 inline int foo(int x) {
56 if (x == FORTYTWO)
57 return FOO_BRANCH(x);
58 return FORTYTWO;
60 #else
61 #define BAR_BRANCH(X) (X) + 2
62 inline int bar(int x) {
63 if (x == FORTYTWO)
64 return BAR_BRANCH(x);
65 return FORTYTWO;
67 #endif
68 // CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm'