252
|
1 // RUN: rm -rf %t
|
|
2 // RUN: mkdir -p %t
|
|
3 // RUN: split-file %s %t
|
|
4 //
|
|
5 // RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/m-a.pcm
|
|
6 // RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/m-b.pcm
|
|
7 // RUN: %clang_cc1 -std=c++23 %t/m.cppm -emit-module-interface -o %t/m.pcm \
|
|
8 // RUN: -fprebuilt-module-path=%t
|
|
9 // RUN: %clang_cc1 -std=c++23 %t/pr63544.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
|
|
10
|
|
11 //--- foo.h
|
|
12
|
|
13 namespace std {
|
|
14 struct strong_ordering {
|
|
15 int n;
|
|
16 constexpr operator int() const { return n; }
|
|
17 static const strong_ordering equal, greater, less;
|
|
18 };
|
|
19 constexpr strong_ordering strong_ordering::equal = {0};
|
|
20 constexpr strong_ordering strong_ordering::greater = {1};
|
|
21 constexpr strong_ordering strong_ordering::less = {-1};
|
|
22 } // namespace std
|
|
23
|
|
24 namespace std {
|
|
25 template <typename _Tp>
|
|
26 class optional {
|
|
27 private:
|
|
28 using value_type = _Tp;
|
|
29 value_type __val_;
|
|
30 bool __engaged_;
|
|
31 public:
|
|
32 constexpr bool has_value() const noexcept
|
|
33 {
|
|
34 return this->__engaged_;
|
|
35 }
|
|
36
|
|
37 constexpr const value_type& operator*() const& noexcept
|
|
38 {
|
|
39 return __val_;
|
|
40 }
|
|
41
|
|
42 optional(_Tp v) : __val_(v) {
|
|
43 __engaged_ = true;
|
|
44 }
|
|
45 };
|
|
46
|
|
47 template <class _Tp>
|
|
48 concept __is_derived_from_optional = requires(const _Tp& __t) { []<class __Up>(const optional<__Up>&) {}(__t); };
|
|
49
|
|
50 template <class _Tp, class _Up>
|
|
51 requires(!__is_derived_from_optional<_Up>)
|
|
52 constexpr strong_ordering
|
|
53 operator<=>(const optional<_Tp>& __x, const _Up& __v) {
|
|
54 return __x.has_value() ? *__x <=> __v : strong_ordering::less;
|
|
55 }
|
|
56 } // namespace std
|
|
57
|
|
58 //--- a.cppm
|
|
59 module;
|
|
60 #include "foo.h"
|
|
61 export module m:a;
|
|
62 export namespace std {
|
|
63 using std::optional;
|
|
64 using std::operator<=>;
|
|
65 }
|
|
66
|
|
67 //--- b.cppm
|
|
68 module;
|
|
69 #include "foo.h"
|
|
70 export module m:b;
|
|
71 export namespace std {
|
|
72 using std::optional;
|
|
73 using std::operator<=>;
|
|
74 }
|
|
75
|
|
76 //--- m.cppm
|
|
77 export module m;
|
|
78 export import :a;
|
|
79 export import :b;
|
|
80
|
|
81 //--- pr63544.cpp
|
|
82 // expected-no-diagnostics
|
|
83 import m;
|
|
84 int pr63544() {
|
|
85 std::optional<int> a(43);
|
|
86 int t{3};
|
|
87 return a<=>t;
|
|
88 }
|