Skip to content

Commit 2a01aeb

Browse files
committed
Fix macos build
1 parent b1547f1 commit 2a01aeb

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
3737
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19)
3838
set(KANGARU_HAS_CPP_MODULES ON)
3939
endif()
40+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
41+
set(KANGARU_HAS_CPP_MODULES OFF)
4042
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
4143
set(KANGARU_HAS_CPP_MODULES OFF) # GCC 15 simply ICE with modules
4244
elseif(MSVC)

include/kangaru/detail/any_source_of.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "concepts.hpp"
66
#include "type_traits.hpp"
77
#include "constructor.hpp"
8+
#include <new>
89

910
#ifndef KANGARU5_MODULES
1011
#include <utility>
@@ -30,13 +31,13 @@ KANGARU5_EXPORT namespace kangaru {
3031
and ... and source_of<detail::type_traits::call_result_t<Function>, Types>
3132
)
3233
explicit(false) constexpr any_source_of(in_place_construct<Function> source) :
33-
source{new detail::type_traits::call_result_t<Function>(source)},
34-
source_vtable{get_vtable_for<detail::type_traits::call_result_t<Function>>()} {}
34+
source_vtable{get_vtable_for<detail::type_traits::call_result_t<Function>>()},
35+
source{new detail::type_traits::call_result_t<Function>(std::move(source))} {}
3536

3637
template<not_self<any_source_of> Source> requires(forwarded_source<Source> and ... and source_of<Source&, Types>)
3738
explicit(false) constexpr any_source_of(Source&& source) :
38-
source{new Source{KANGARU5_FWD(source)}},
39-
source_vtable{get_vtable_for<std::remove_cvref_t<Source>>()} {}
39+
source_vtable{get_vtable_for<std::remove_cvref_t<Source>>()},
40+
source{new Source{KANGARU5_FWD(source)}} {}
4041

4142
template<not_self<any_source_of> Source> requires(forwarded_source<Source> and ... and source_of<Source&, Types>)
4243
constexpr auto operator=(Source&& rhs) -> any_source_of& {
@@ -52,11 +53,14 @@ KANGARU5_EXPORT namespace kangaru {
5253
any_source_of(any_source_of const&) = delete;
5354
auto operator=(any_source_of const&) -> any_source_of& = delete;
5455

55-
constexpr any_source_of(any_source_of&& other) noexcept : source{std::exchange(other.source, nullptr)}, source_vtable{std::exchange(other.source_vtable, {})} {}
56+
constexpr any_source_of(any_source_of&& other) noexcept :
57+
source_vtable{std::exchange(other.source_vtable, {})},
58+
source{std::exchange(other.source, nullptr)} {}
5659

5760
constexpr auto operator=(any_source_of&& rhs) -> any_source_of& {
58-
std::ranges::swap(source, rhs.source);
61+
if (this == &rhs) return *this;
5962
std::swap(source_vtable, rhs.source_vtable);
63+
std::swap(source, rhs.source);
6064
return *this;
6165
}
6266

include/kangaru/detail/heap_storage.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace kangaru {
3333
ptr{std::exchange(other.ptr, nullptr)}, deleter{std::exchange(other.deleter, nullptr)} {}
3434

3535
constexpr auto operator=(runtime_dynamic_storage&& rhs) noexcept -> runtime_dynamic_storage& {
36+
if (this == &rhs) return *this;
3637
std::ranges::swap(ptr, rhs.ptr);
3738
std::ranges::swap(deleter, rhs.deleter);
3839
return *this;
@@ -112,6 +113,7 @@ namespace kangaru {
112113
allocator{std::move(other.allocator)}, container{std::move(other.container)} {}
113114

114115
constexpr auto operator=(basic_heap_storage&& rhs) noexcept -> basic_heap_storage& {
116+
if (this == &rhs) return *this;
115117
std::ranges::swap(allocator, rhs.allocator);
116118
std::ranges::swap(container, rhs.container);
117119
return *this;

include/kangaru/detail/polymorphic_source.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ namespace kangaru {
9393
}
9494

9595
template<injectable T>
96-
constexpr auto operator=(polymorphic_source<T> const& other) -> type_erased_source_reference& {
97-
source = other.source;
96+
constexpr auto operator=(polymorphic_source<T> const& rhs) -> type_erased_source_reference& {
97+
source = rhs.source;
9898

9999
std::construct_at(
100100
static_cast<function_container<T>*>(static_cast<void*>(function_container_type_erased)),
101-
other.provide_function
101+
rhs.provide_function
102102
);
103103

104104
return *this;

tests/src/5-modular-source.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,51 @@ namespace kangaru {
165165

166166
template<source... Sources, source Source>
167167
inline constexpr auto make_modular_source(Source source) {
168-
return modular_source<Source, kangaru::constructor_function<Sources>...>{std::move(source), kangaru::constructor_function<Sources>{}...};
168+
return modular_source<Source, kangaru::constructor_function<Sources>...>{
169+
std::move(source),
170+
kangaru::constructor_function<Sources>{}...
171+
};
169172
}
170173

171174
template<source... Sources>
172175
inline constexpr auto make_modular_source() {
173-
return modular_source<none_source, kangaru::constructor_function<Sources>...>{none_source{}, kangaru::constructor_function<Sources>{}...};
176+
return modular_source<none_source, kangaru::constructor_function<Sources>...>{
177+
none_source{},
178+
kangaru::constructor_function<Sources>{}...
179+
};
174180
}
175181

176182
template<source Source, typename... Lambdas>
177183
inline constexpr auto make_modular_source_in_place(Source source, Lambdas... lambdas) {
178-
return in_place_construct{[&]{ return modular_source<Source, Lambdas...>{std::move(source), lambdas...}; }};
184+
return in_place_construct{
185+
[source = std::move(source), ...lambdas = std::move(lambdas)]() mutable {
186+
return modular_source<Source, Lambdas...>{std::move(source), lambdas...};
187+
},
188+
};
179189
}
180190

181191
template<source... Sources, source Source>
182192
inline constexpr auto make_modular_source_in_place(Source source) {
183-
return in_place_construct{[&]{ return modular_source<Source, kangaru::constructor_function<Sources>...>{std::move(source), kangaru::constructor_function<Sources>{}...}; }};
193+
return in_place_construct{
194+
[source = std::move(source)]() mutable {
195+
return modular_source<Source, kangaru::constructor_function<Sources>...>{
196+
std::move(source),
197+
kangaru::constructor_function<Sources>{}...
198+
};
199+
},
200+
};
184201
}
185202

186203
template<source... Sources>
187204
inline constexpr auto make_modular_source_in_place() {
188-
return in_place_construct{[&]{ return modular_source<none_source, kangaru::constructor_function<Sources>...>{none_source{}, kangaru::constructor_function<Sources>{}...}; }};
205+
return in_place_construct{
206+
[] {
207+
return modular_source<none_source, kangaru::constructor_function<Sources>...>{
208+
none_source{},
209+
kangaru::constructor_function<Sources>{}...
210+
};
211+
},
212+
};
189213
}
190214

191215
template<typename... Modules>

0 commit comments

Comments
 (0)