Skip to content

Commit d6ca7b9

Browse files
committed
[Modules] initializers.cpp test fix
The module contents should not contain preprocessor directives. The contents should be already preprocessed. Duplicate the modules instead to propose 2 versions: one with the namespace ns and one without.
1 parent 72bc062 commit d6ca7b9

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

clang/test/Modules/initializers.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// instantiation for v<int> in one of the two headers, because we will only
4949
// parse one of the two get() functions.
5050

51+
#ifdef NS
5152
#pragma clang module build m
5253
module m {
5354
module a {
@@ -60,9 +61,7 @@ module m {
6061
#pragma clang module begin m.a
6162
inline int non_trivial() { return 3; }
6263

63-
#ifdef NS
6464
namespace ns {
65-
#endif
6665

6766
int a = non_trivial();
6867
inline int b = non_trivial();
@@ -102,12 +101,64 @@ inline void use(bool b, ...) {
102101
X<int>::e<int>, X<int>::f<int>, X<int>::g<int>, X<int>::h<int>);
103102
}
104103

105-
#ifdef NS
106104
}
107-
#endif
108105

109106
#pragma clang module end
110107
#pragma clang module endbuild
108+
#else
109+
#pragma clang module build m
110+
module m {
111+
module a {
112+
header "foo.h" { size 123 mtime 456789 }
113+
}
114+
module b {}
115+
}
116+
117+
#pragma clang module contents
118+
#pragma clang module begin m.a
119+
inline int non_trivial() { return 3; }
120+
121+
int a = non_trivial();
122+
inline int b = non_trivial();
123+
thread_local int c = non_trivial();
124+
inline thread_local int d = non_trivial();
125+
126+
template<typename U> int e = non_trivial();
127+
template<typename U> inline int f = non_trivial();
128+
template<typename U> thread_local int g = non_trivial();
129+
template<typename U> inline thread_local int h = non_trivial();
130+
131+
inline int unused = 123; // should not be emitted
132+
133+
template<typename T> struct X {
134+
static int a;
135+
static inline int b = non_trivial();
136+
static thread_local int c;
137+
static inline thread_local int d = non_trivial();
138+
139+
template<typename U> static int e;
140+
template<typename U> static inline int f = non_trivial();
141+
template<typename U> static thread_local int g;
142+
template<typename U> static inline thread_local int h = non_trivial();
143+
144+
static inline int unused = 123; // should not be emitted
145+
};
146+
147+
template<typename T> int X<T>::a = non_trivial();
148+
template<typename T> thread_local int X<T>::c = non_trivial();
149+
template<typename T> template<typename U> int X<T>::e = non_trivial();
150+
template<typename T> template<typename U> thread_local int X<T>::g = non_trivial();
151+
152+
inline void use(bool b, ...) {
153+
if (b) return;
154+
use(true, e<int>, f<int>, g<int>, h<int>,
155+
X<int>::a, X<int>::b, X<int>::c, X<int>::d,
156+
X<int>::e<int>, X<int>::f<int>, X<int>::g<int>, X<int>::h<int>);
157+
}
158+
159+
#pragma clang module end
160+
#pragma clang module endbuild
161+
#endif
111162

112163
#if IMPORT == 1
113164
// Import the module and the m.a submodule; runs the ordered initializers and

0 commit comments

Comments
 (0)