Skip to content

Commit 1fb2331

Browse files
committed
[NFC] [C++20] [Modules] Add a test to show the ability to skip bodies for import first and include later
For the common pattern: ```C++ module; export module a; ... ``` ```C++ // a.cpp import a; ``` In this case, we're already able to skip parsing the body of some declarations in a.cpp. Add a test to show the ability.
1 parent 4f683b1 commit 1fb2331

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

clang/test/Modules/skip-body.cppm

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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/a.cppm -emit-reduced-module-interface -o %t/a.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/a.cpp -fmodule-file=a=%t/a.pcm -ast-dump | FileCheck %s
7+
8+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
9+
// RUN: %clang_cc1 -std=c++20 %t/a.cpp -fmodule-file=a=%t/a.pcm -ast-dump | FileCheck %s
10+
11+
//--- a.h
12+
namespace a {
13+
class A {
14+
public:
15+
int aaaa;
16+
17+
int get() {
18+
return aaaa;
19+
}
20+
};
21+
22+
23+
template <class T>
24+
class B {
25+
public:
26+
B(T t): t(t) {}
27+
T t;
28+
};
29+
30+
using BI = B<int>;
31+
32+
inline int get(A a, BI b) {
33+
return a.get() + b.t;
34+
}
35+
36+
}
37+
38+
//--- a.cppm
39+
module;
40+
#include "a.h"
41+
42+
export module a;
43+
44+
namespace a {
45+
export using ::a::A;
46+
export using ::a::get;
47+
export using ::a::BI;
48+
}
49+
50+
//--- a.cpp
51+
import a;
52+
#include "a.h"
53+
54+
int test() {
55+
a::A aa;
56+
a::BI bb(43);
57+
return get(aa, bb);
58+
}
59+
60+
// CHECK-NOT: DefinitionData
61+
// CHECK: FunctionDecl {{.*}} get 'int (A, BI)' {{.*}}
62+
// CHECK-NOT: CompoundStmt
63+
// CHECK: FunctionDecl {{.*}} test {{.*}}

0 commit comments

Comments
 (0)