| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: mkdir %t |
| 3 |
// RUN: split-file %s %t |
| 4 |
// RUN: mkdir %t/tmp |
| 5 |
|
| 6 |
// RUN: %clang_cc1 -std=c++26 %t/std.cppm -emit-module-interface -o %t/std.pcm |
| 7 |
// RUN: %clang_cc1 -std=c++26 %t/optional.cppm -emit-module-interface -o %t/optional.pcm \ |
| 8 |
// RUN: -fmodule-file=std=%t/std.pcm |
| 9 |
// RUN: %clang_cc1 -std=c++26 %t/date.format.cppm -emit-module-interface -o %t/date.format.pcm \ |
| 10 |
// RUN: -fmodule-file=std=%t/std.pcm \ |
| 11 |
// RUN: -fmodule-file=bopt.optional=%t/optional.pcm |
| 12 |
// RUN: %clang_cc1 -std=c++26 %t/annotated.cppm -emit-module-interface -o %t/annotated.pcm \ |
| 13 |
// RUN: -fmodule-file=std=%t/std.pcm \ |
| 14 |
// RUN: -fmodule-file=bopt.optional=%t/optional.pcm \ |
| 15 |
// RUN: -fmodule-file=ldgr:date.format=%t/date.format.pcm |
| 16 |
// RUN: %clang_cc1 -std=c++26 %t/annotated.format.cppm -emit-module-interface -o %t/annotated.format.pcm \ |
| 17 |
// RUN: -fmodule-file=std=%t/std.pcm \ |
| 18 |
// RUN: -fmodule-file=bopt.optional=%t/optional.pcm \ |
| 19 |
// RUN: -fmodule-file=ldgr:date.format=%t/date.format.pcm \ |
| 20 |
// RUN: -fmodule-file=ldgr:annotated=%t/annotated.pcm |
| 21 |
// RUN: %clang_cc1 -std=c++26 %t/date.test.cppm -emit-module-interface -o %t/date.test.pcm \ |
| 22 |
// RUN: -fmodule-file=std=%t/std.pcm \ |
| 23 |
// RUN: -fmodule-file=bopt.optional=%t/optional.pcm \ |
| 24 |
// RUN: -fmodule-file=ldgr:date.format=%t/date.format.pcm \ |
| 25 |
// RUN: -fmodule-file=ldgr:annotated=%t/annotated.pcm \ |
| 26 |
// RUN: -fmodule-file=ldgr:annotated.format=%t/annotated.format.pcm |
| 27 |
// RUN: %clang_cc1 -std=c++26 -w %t/annotated.test.cpp -fsyntax-only -verify \ |
| 28 |
// RUN: -fmodule-file=std=%t/std.pcm \ |
| 29 |
// RUN: -fmodule-file=bopt.optional=%t/optional.pcm \ |
| 30 |
// RUN: -fmodule-file=ldgr:date.format=%t/date.format.pcm \ |
| 31 |
// RUN: -fmodule-file=ldgr:annotated=%t/annotated.pcm \ |
| 32 |
// RUN: -fmodule-file=ldgr:annotated.format=%t/annotated.format.pcm \ |
| 33 |
// RUN: -fmodule-file=ldgr:date.testlib=%t/date.test.pcm |
| 34 |
|
| 35 |
//--- std.cppm |
| 36 |
module; |
| 37 |
namespace std { |
| 38 |
inline namespace __1 { |
| 39 |
template <class _Tp> _Tp forward(_Tp); |
| 40 |
template <class... _Args> |
| 41 |
void __invoke(_Args... __args) noexcept( |
| 42 |
noexcept(__builtin_invoke(forward(__args)...))); |
| 43 |
using string = char; |
| 44 |
struct in_place_t { |
| 45 |
} in_place; |
| 46 |
template <typename...> struct __traits; |
| 47 |
struct Trans_NS___visitation___base { |
| 48 |
template <class _Visitor, class... _Vs> |
| 49 |
static void __visit_alt(_Visitor, _Vs... __vs) { |
| 50 |
__make_fmatrix<_Visitor, decltype(__vs)...>; |
| 51 |
} |
| 52 |
struct __dispatcher { |
| 53 |
template <class _Fp, class... _Vs> static void __dispatch(_Vs... __vs) { |
| 54 |
_Fp __f; |
| 55 |
__invoke(__f, __vs...); |
| 56 |
} |
| 57 |
}; |
| 58 |
template <class _Fp, class... _Vs> static void __make_dispatch() { |
| 59 |
__dispatcher::__dispatch<_Fp, _Vs...>; |
| 60 |
} |
| 61 |
template <class _Fp, class... _Vs> static void __make_fmatrix_impl() { |
| 62 |
__make_dispatch<_Fp, _Vs...>; |
| 63 |
} |
| 64 |
template <class _Fp, class... _Vs> static void __make_fmatrix() { |
| 65 |
__make_fmatrix_impl<_Fp, _Vs...>; |
| 66 |
} |
| 67 |
}; |
| 68 |
template <class> class __dtor; |
| 69 |
template <class... _Types> struct __dtor<__traits<_Types...>> { |
| 70 |
~__dtor() { |
| 71 |
Trans_NS___visitation___base::__visit_alt([](auto) {}, this); |
| 72 |
} |
| 73 |
}; |
| 74 |
struct __move_constructor : __dtor<__traits<>> {}; |
| 75 |
struct __assignment : __move_constructor {}; |
| 76 |
struct __impl : __assignment {}; |
| 77 |
template <class> struct variant { |
| 78 |
__impl __impl_; |
| 79 |
}; |
| 80 |
} |
| 81 |
} |
| 82 |
export module std; |
| 83 |
export namespace std { |
| 84 |
using std::forward; |
| 85 |
using std::in_place; |
| 86 |
using std::in_place_t; |
| 87 |
using std::string; |
| 88 |
using std::variant; |
| 89 |
} |
| 90 |
|
| 91 |
//--- optional.cppm |
| 92 |
export module bopt.optional; |
| 93 |
import std; |
| 94 |
namespace bopt { |
| 95 |
template <class T> struct wrapper { |
| 96 |
template <class Func> wrapper(int, Func f) : value(std::forward(f)()) {} |
| 97 |
T value; |
| 98 |
}; |
| 99 |
template <class T> struct optional_base { |
| 100 |
struct union_t { |
| 101 |
T value_; |
| 102 |
}; |
| 103 |
struct repr { |
| 104 |
template <class OtherValue> |
| 105 |
repr(OtherValue) : un_{0, [] { return union_t{}; }} {} |
| 106 |
wrapper<union_t> un_; |
| 107 |
}; |
| 108 |
template <class... Args> |
| 109 |
optional_base(std::in_place_t, Args... args) : repr_{args...} {} |
| 110 |
repr repr_; |
| 111 |
}; |
| 112 |
export template <class T> struct optional : optional_base<T> { |
| 113 |
optional(); |
| 114 |
template <class U> optional(U) : optional_base<T>{std::in_place, 0} {} |
| 115 |
template <class U> constexpr void operator=(U) { |
| 116 |
[] {}; |
| 117 |
} |
| 118 |
}; |
| 119 |
} |
| 120 |
|
| 121 |
//--- date.format.cppm |
| 122 |
module ldgr:date.format; |
| 123 |
import bopt.optional; |
| 124 |
namespace ldgr { |
| 125 |
struct date_format { |
| 126 |
template <class S> static int parse(S s) { bopt::optional<int> year{s}; } |
| 127 |
}; |
| 128 |
} |
| 129 |
|
| 130 |
//--- annotated.cppm |
| 131 |
module ldgr:annotated; |
| 132 |
import std; |
| 133 |
import bopt.optional; |
| 134 |
struct lot_annotation { |
| 135 |
using valuation_expr_t = std::variant<std::string>; |
| 136 |
bopt::optional<valuation_expr_t> valuation_expr_; |
| 137 |
}; |
| 138 |
struct annotated_amount { |
| 139 |
lot_annotation lot_annotation_; |
| 140 |
}; |
| 141 |
|
| 142 |
//--- annotated.format.cppm |
| 143 |
module ldgr:annotated.format; |
| 144 |
import :date.format; |
| 145 |
import :annotated; |
| 146 |
namespace ldgr { |
| 147 |
struct annotated_format { |
| 148 |
static annotated_amount parse_default() { |
| 149 |
bopt::optional<int> date; |
| 150 |
date = date_format::parse(0); |
| 151 |
} |
| 152 |
}; |
| 153 |
} |
| 154 |
|
| 155 |
//--- date.test.cppm |
| 156 |
module ldgr:date.testlib; |
| 157 |
import :date.format; |
| 158 |
void date_from_string() { ldgr::date_format::parse(0); } |
| 159 |
|
| 160 |
//--- annotated.test.cpp |
| 161 |
// expected-no-diagnostics |
| 162 |
module ldgr:annotatedtest; |
| 163 |
import :annotated.format; |
| 164 |
import :date.testlib; |
| 165 |
int main() { ldgr::annotated_format::parse_default(); } |