Debian Codegraph @

clang/test/Modules/pr62943.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/a.cppm -emit-module-interface -o %t/a.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm
7 // RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface \
8 // RUN: -fprebuilt-module-path=%t -o %t/c.pcm
9 // RUN: %clang_cc1 -std=c++20 %t/use.cpp -fprebuilt-module-path=%t \
10 // RUN: -fsyntax-only -verify
11
12 // Test again with reduced BMI.
13 // RUN: rm -rf %t
14 // RUN: mkdir -p %t
15 // RUN: split-file %s %t
16 //
17 // RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
18 // RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm
19 // RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-reduced-module-interface \
20 // RUN: -fprebuilt-module-path=%t -o %t/c.pcm
21 // RUN: %clang_cc1 -std=c++20 %t/use.cpp -fprebuilt-module-path=%t \
22 // RUN: -fsyntax-only -verify
23
24 //--- foo.h
25 #ifndef FOO_H
26 #define FOO_H
27
28 template<class _Tp>
29 concept __has_member_value_type = requires { typename _Tp::value_type; };
30
31 template<class _Tp>
32 concept __has_member_element_type = requires { typename _Tp::element_type; };
33
34 template <class _Tp>
35 inline constexpr bool is_object_v = __is_object(_Tp);
36
37 template<class> struct __cond_value_type {};
38
39 template<class _Tp>
40 requires is_object_v<_Tp>
41 struct __cond_value_type<_Tp> { using value_type = bool; };
42
43 template<class> struct indirectly_readable_traits {
44 static constexpr int value = false;
45 };
46 #endif
47
48 //--- foo.member_value_type.h
49 #include "foo.h"
50 template<__has_member_value_type _Tp>
51 struct indirectly_readable_traits<_Tp> : __cond_value_type<typename _Tp::value_type> {
52 static constexpr int value = false;
53 };
54
55 //--- foo.memeber_element_type.h
56 #include "foo.h"
57 template<__has_member_element_type _Tp>
58 struct indirectly_readable_traits<_Tp> : __cond_value_type<typename _Tp::element_type> {
59 static constexpr int value = false;
60 };
61
62 template<__has_member_value_type _Tp>
63 requires __has_member_element_type<_Tp>
64 struct indirectly_readable_traits<_Tp> {
65 static constexpr int value = true;
66 };
67
68 //--- foo.a.h
69 #include "foo.h"
70 #include "foo.member_value_type.h"
71 #include "foo.memeber_element_type.h"
72 template <typename T>
73 using AType = indirectly_readable_traits<T>;
74
75 //--- a.cppm
76 module;
77 #include "foo.a.h"
78 export module a;
79
80 export using ::AType;
81
82 //--- b.cppm
83 module;
84 #include "foo.h"
85 #include "foo.memeber_element_type.h"
86 export module b;
87
88 //--- c.cppm
89 export module c;
90
91 export import a;
92 export import b;
93
94 //--- use.cpp
95 // expected-no-diagnostics
96 import c;
97
98 template <typename T>
99 class U {
100 public:
101 using value_type = T;
102 using element_type = T;
103 };
104
105 template <typename T>
106 class V {
107 public:
108 };
109
110 static_assert(!AType<V<int*>>::value);
111 static_assert(AType<U<int**>>::value);