Commit 788ab800 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 8

Don't try and instantiate an invalid function in DiscriminatedPtrDetail

Summary:
THe issue is quite simple: Regardless of the control flow, the previous implementation of this was instantiating `ApplyVisitor1<V,R>` which declares a return type, but never returns.
This refactors `ApplyVisitor1` and `ApplyConstVisitor1` so that the part of the control flow that was previously never reached simply doesn't exist anymore.

Reviewed By: yfeldblum

Differential Revision: D3479584

fbshipit-source-id: 605a48e39bba6dc14df1af1e76b55ea60f3e69d5
parent b0883076
...@@ -110,53 +110,59 @@ struct ConstVisitorResult { ...@@ -110,53 +110,59 @@ struct ConstVisitorResult {
typename ConstVisitorResult1<V,Types>::type...>::type type; typename ConstVisitorResult1<V,Types>::type...>::type type;
}; };
template <typename V, typename R, typename... Types> struct ApplyVisitor1; template <size_t index, typename V, typename R, typename... Types>
struct ApplyVisitor1;
template <typename V, typename R> template <typename V, typename R, typename T, typename... Types>
struct ApplyVisitor1<V, R> { struct ApplyVisitor1<1, V, R, T, Types...> {
R operator()(size_t /* index */, V&& /* visitor */, void* /* ptr */) const { R operator()(size_t, V&& visitor, void* ptr) const {
CHECK(false); // NOTREACHED return visitor(static_cast<T*>(ptr));
} }
}; };
template <typename V, typename R, typename T, typename... Types> template <size_t index, typename V, typename R, typename T, typename... Types>
struct ApplyVisitor1<V, R, T, Types...> { struct ApplyVisitor1<index, V, R, T, Types...> {
R operator()(size_t index, V&& visitor, void* ptr) const { R operator()(size_t runtimeIndex, V&& visitor, void* ptr) const {
return (index == 1 ? visitor(static_cast<T*>(ptr)) : return runtimeIndex == 1
ApplyVisitor1<V, R, Types...>()( ? visitor(static_cast<T*>(ptr))
index - 1, std::forward<V>(visitor), ptr)); : ApplyVisitor1<index - 1, V, R, Types...>()(
runtimeIndex - 1, std::forward<V>(visitor), ptr);
} }
}; };
template <typename V, typename R, typename... Types> struct ApplyConstVisitor1; template <size_t index, typename V, typename R, typename... Types>
struct ApplyConstVisitor1;
template <typename V, typename R> template <typename V, typename R, typename T, typename... Types>
struct ApplyConstVisitor1<V, R> { struct ApplyConstVisitor1<1, V, R, T, Types...> {
R operator()(size_t /* index */, V&& /* visitor */, void* /* ptr */) const { R operator()(size_t, V&& visitor, void* ptr) const {
CHECK(false); // NOTREACHED return visitor(static_cast<const T*>(ptr));
} }
}; };
template <typename V, typename R, typename T, typename... Types> template <size_t index, typename V, typename R, typename T, typename... Types>
struct ApplyConstVisitor1<V, R, T, Types...> { struct ApplyConstVisitor1<index, V, R, T, Types...> {
R operator()(size_t index, V&& visitor, void* ptr) const { R operator()(size_t runtimeIndex, V&& visitor, void* ptr) const {
return (index == 1 ? visitor(static_cast<const T*>(ptr)) : return runtimeIndex == 1
ApplyConstVisitor1<V, R, Types...>()( ? visitor(static_cast<const T*>(ptr))
index - 1, std::forward<V>(visitor), ptr)); : ApplyConstVisitor1<index - 1, V, R, Types...>()(
runtimeIndex - 1, std::forward<V>(visitor), ptr);
} }
}; };
template <typename V, typename... Types> template <typename V, typename... Types>
struct ApplyVisitor using ApplyVisitor = ApplyVisitor1<
: ApplyVisitor1< sizeof...(Types),
V, typename VisitorResult<V, Types...>::type, Types...> { V,
}; typename VisitorResult<V, Types...>::type,
Types...>;
template <typename V, typename... Types> template <typename V, typename... Types>
struct ApplyConstVisitor using ApplyConstVisitor = ApplyConstVisitor1<
: ApplyConstVisitor1< sizeof...(Types),
V, typename ConstVisitorResult<V, Types...>::type, Types...> { V,
}; typename ConstVisitorResult<V, Types...>::type,
Types...>;
} // namespace dptr_detail } // namespace dptr_detail
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment