Skip to content

Instantly share code, notes, and snippets.

@Lastique
Created April 21, 2017 09:49
Show Gist options
  • Save Lastique/aaf7e3fd2203e24dfab8d355e72201f8 to your computer and use it in GitHub Desktop.
Save Lastique/aaf7e3fd2203e24dfab8d355e72201f8 to your computer and use it in GitHub Desktop.
Patch to fix Boost.Context 1.64 for gcc 4.9
From e66b64c1ec0bcc496d3d9212d66959351a5af551 Mon Sep 17 00:00:00 2001
From: Andrey Semashev <andrey.semashev@gmail.com>
Date: Thu, 20 Apr 2017 22:59:55 +0300
Subject: [PATCH] Fix compilation with gcc 4.9.
The compiler apparently has problems with template ordering, so:
- Remove callcc overloads that have no arguments for the function. These
overloads are ambiguous with the overloads taking variadic args. The
no-args case is covered by the variadic iverloads anyway.
- Enforce overload resolution with SFINAE. Disable instantiating templated
overloads with arguments for which non-templated version of callcc is
provided.
- Update friend declarations of callcc in continuation to match the callcc
function signatures, including the template arguments. Otherwise, friend
declarations declare additional overloads of callcc which ambiguate
overload resolution. To do this, the callcc functions have to be
forward-declared before the continuation class (default template arguments
cannot be specified in friend declarations).
---
boost/context/continuation.hpp | 95 +++++++++++++++++++---------------
1 file changed, 52 insertions(+), 43 deletions(-)
Index: boost_1_64_0/boost/context/continuation.hpp
===================================================================
--- boost_1_64_0.orig/boost/context/continuation.hpp 2017-04-20 23:15:28.139768406 +0300
+++ boost_1_64_0/boost/context/continuation.hpp 2017-04-20 23:15:28.135768369 +0300
@@ -270,6 +270,31 @@ detail::transfer_t context_ontop_void( d
#endif
}
+class continuation;
+
+template<
+ typename StackAlloc,
+ typename Fn,
+ typename ... Arg,
+ typename = detail::disable_overload< preallocated, StackAlloc >
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename = detail::disable_overload< segmented_stack, StackAlloc >
+#endif
+>
+continuation
+callcc( std::allocator_arg_t, StackAlloc salloc, Fn && fn, Arg ... arg);
+
+template<
+ typename StackAlloc,
+ typename Fn,
+ typename ... Arg
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename = detail::disable_overload< segmented_stack, StackAlloc >
+#endif
+>
+continuation
+callcc( std::allocator_arg_t, preallocated palloc, StackAlloc salloc, Fn && fn, Arg ... arg);
+
class continuation {
private:
template< typename Ctx, typename StackAlloc, typename Fn >
@@ -283,22 +308,29 @@ private:
friend detail::transfer_t
context_ontop_void( detail::transfer_t);
- template< typename StackAlloc, typename Fn, typename ... Arg >
+ template<
+ typename StackAlloc,
+ typename Fn,
+ typename ... Arg,
+ typename
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename
+#endif
+ >
friend continuation
callcc( std::allocator_arg_t, StackAlloc, Fn &&, Arg ...);
- template< typename StackAlloc, typename Fn, typename ... Arg >
+ template<
+ typename StackAlloc,
+ typename Fn,
+ typename ... Arg
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename
+#endif
+ >
friend continuation
callcc( std::allocator_arg_t, preallocated, StackAlloc, Fn &&, Arg ...);
- template< typename StackAlloc, typename Fn >
- friend continuation
- callcc( std::allocator_arg_t, StackAlloc, Fn &&);
-
- template< typename StackAlloc, typename Fn >
- friend continuation
- callcc( std::allocator_arg_t, preallocated, StackAlloc, Fn &&);
-
detail::transfer_t t_{ nullptr, nullptr };
continuation( detail::fcontext_t fctx) noexcept :
@@ -447,11 +479,11 @@ public:
}
};
-// Arg
template<
typename Fn,
typename ... Arg,
- typename = detail::disable_overload< continuation, Fn >
+ typename = detail::disable_overload< continuation, Fn >,
+ typename = detail::disable_overload< std::allocator_arg_t, Fn >
>
continuation
callcc( Fn && fn, Arg ... arg) {
@@ -463,7 +495,11 @@ callcc( Fn && fn, Arg ... arg) {
template<
typename StackAlloc,
typename Fn,
- typename ... Arg
+ typename ... Arg,
+ typename // = detail::disable_overload< preallocated, StackAlloc >
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename // = detail::disable_overload< segmented_stack, StackAlloc >
+#endif
>
continuation
callcc( std::allocator_arg_t, StackAlloc salloc, Fn && fn, Arg ... arg) {
@@ -478,6 +514,9 @@ template<
typename StackAlloc,
typename Fn,
typename ... Arg
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ , typename // = detail::disable_overload< segmented_stack, StackAlloc >
+#endif
>
continuation
callcc( std::allocator_arg_t, preallocated palloc, StackAlloc salloc, Fn && fn, Arg ... arg) {
@@ -488,36 +527,6 @@ callcc( std::allocator_arg_t, preallocat
std::forward< Arg >( arg) ... );
}
-// void
-template<
- typename Fn,
- typename = detail::disable_overload< continuation, Fn >
->
-continuation
-callcc( Fn && fn) {
- return callcc(
- std::allocator_arg, fixedsize_stack(),
- std::forward< Fn >( fn) );
-}
-
-template< typename StackAlloc, typename Fn >
-continuation
-callcc( std::allocator_arg_t, StackAlloc salloc, Fn && fn) {
- using Record = detail::record< continuation, StackAlloc, Fn >;
- return continuation{
- detail::context_create< Record >(
- salloc, std::forward< Fn >( fn) ) }.resume();
-}
-
-template< typename StackAlloc, typename Fn >
-continuation
-callcc( std::allocator_arg_t, preallocated palloc, StackAlloc salloc, Fn && fn) {
- using Record = detail::record< continuation, StackAlloc, Fn >;
- return continuation{
- detail::context_create< Record >(
- palloc, salloc, std::forward< Fn >( fn) ) }.resume();
-}
-
#if defined(BOOST_USE_SEGMENTED_STACKS)
template<
typename Fn,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment