Debian Codegraph @

clang/test/Modules/lambdas.cppm

raw
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 %t/lambdas.cppm -emit-module-interface \
6 // RUN: -o %t/lambdas.pcm
7 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only \
8 // RUN: -verify
9 //
10 // RUN: %clang_cc1 -std=c++20 %t/lambdas2.cppm -emit-module-interface \
11 // RUN: -o %t/lambdas2.pcm
12 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only \
13 // RUN: -verify -DUSE_LAMBDA2
14 //
15 // Test again with reduced BMI.
16 // RUN: rm -rf %t
17 // RUN: mkdir -p %t
18 // RUN: split-file %s %t
19 //
20 // RUN: %clang_cc1 -std=c++20 %t/lambdas.cppm -emit-reduced-module-interface \
21 // RUN: -o %t/lambdas.pcm
22 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only \
23 // RUN: -verify
24 //
25 // RUN: %clang_cc1 -std=c++20 %t/lambdas2.cppm -emit-reduced-module-interface \
26 // RUN: -o %t/lambdas2.pcm
27 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only \
28 // RUN: -verify -DUSE_LAMBDA2
29
30 //--- lambdas.h
31 auto l1 = []() constexpr -> int {
32 return 43;
33 };
34 //
35 auto l2 = []() constexpr -> double {
36 return 3.0;
37 };
38 //
39 auto l3 = [](auto i) constexpr -> int {
40 return int(i);
41 };
42 //
43 auto l4 = [](auto i, auto u) constexpr -> int {
44 return i + u;
45 };
46
47 //--- lambdas.cppm
48 module;
49 #include "lambdas.h"
50 export module lambdas;
51 export using ::l1;
52 export using ::l2;
53 export using ::l3;
54 export using ::l4;
55
56 //--- lambdas2.cppm
57 export module lambdas2;
58 export {
59 #include "lambdas.h"
60 }
61
62 //--- Use.cpp
63 // expected-no-diagnostics
64 #ifndef USE_LAMBDA2
65 import lambdas;
66 #else
67 import lambdas2;
68 #endif
69
70 static_assert(l1.operator()() == 43);
71
72 static_assert(l2.operator()() == 3.0);
73
74 static_assert(l3.operator()(8.4) == 8);
75
76 static_assert(l4(4, 12) == 16);
77 static_assert(l4(5, 20) == 25);