Skip to content

Commit

Permalink
fixed potential undefined behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
gracicot committed Feb 16, 2016
1 parent f831ef6 commit 7c6bf2f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/kangaru/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ struct Container {
delete static_cast<T*>(i);
}

template<typename T, typename... Args, enable_if<std::is_constructible<T, Args...>> = 0>
static instance_ptr<T> makeInstancePtr(Args&&... args) {
return instance_ptr<T>{new T(std::forward<Args>(args)...), &Container::deleter<T>};
template<typename T, typename C = T, typename... Args, enable_if<std::is_constructible<T, Args...>> = 0>
static instance_ptr<C> makeInstancePtr(Args&&... args) {
return instance_ptr<T>{new T(std::forward<Args>(args)...), &Container::deleter<C>};
}

template<typename T, typename... Args, disable_if<std::is_constructible<T, Args...>> = 0>
static instance_ptr<T> makeInstancePtr(Args&&... args) {
return instance_ptr<T>{new T{std::forward<Args>(args)...}, &Container::deleter<T>};
template<typename T, typename C = T, typename... Args, disable_if<std::is_constructible<T, Args...>> = 0>
static instance_ptr<C> makeInstancePtr(Args&&... args) {
return instance_ptr<T>{new T{std::forward<Args>(args)...}, &Container::deleter<C>};
}

public:
Expand Down Expand Up @@ -117,7 +117,7 @@ struct Container {
void save_instance_helper(instance_ptr<T> service) {
using ServiceOverride = detail::ServiceOverride<T, Override>;

_services[detail::type_id<Override>].emplace_back(static_cast<instance_ptr<Override>>(makeInstancePtr<ServiceOverride>(*service)));
_services[detail::type_id<Override>].emplace_back(makeInstancePtr<ServiceOverride, Override>(*service));
save_instance_helper<T, Others...>(std::move(service));
}

Expand Down

0 comments on commit 7c6bf2f

Please sign in to comment.