Debian Codegraph @

clang/test/Modules/recursive-instantiations.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/type_traits.cppm -emit-module-interface -o %t/type_traits.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/test.cpp -fprebuilt-module-path=%t -verify
7
8 //--- type_traits.cppm
9 export module type_traits;
10
11 export template <typename T>
12 constexpr bool is_pod_v = __is_pod(T);
13
14 //--- test.cpp
15 // expected-no-diagnostics
16 import type_traits;
17 // Base is either void or wrapper<T>.
18 template <class Base> struct wrapper : Base {};
19 template <> struct wrapper<void> {};
20
21 // wrap<0>::type<T> is wrapper<T>, wrap<1>::type<T> is wrapper<wrapper<T>>,
22 // and so on.
23 template <int N>
24 struct wrap {
25 template <class Base>
26 using type = wrapper<typename wrap<N-1>::template type<Base>>;
27 };
28
29 template <>
30 struct wrap<0> {
31 template <class Base>
32 using type = wrapper<Base>;
33 };
34
35 inline constexpr int kMaxRank = 40;
36 template <int N, class Base = void>
37 using rank = typename wrap<N>::template type<Base>;
38 using rank_selector_t = rank<kMaxRank>;
39
40 static_assert(is_pod_v<rank_selector_t>, "Must be POD");