Skip to content

Commit 2f32476

Browse files
committed
Fix compilation with MSVC 2019 in C++17 mode
1 parent d10ba44 commit 2f32476

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

cmake/FindCoroutines.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ if(find_final)
157157
set(_CXX_COROUTINES_HAVE_HEADER ${_CXX_COROUTINES_HAVE_HEADER_WITH_FLAG})
158158
cmake_pop_check_state()
159159
endif()
160+
check_cxx_source_compiles("#include <coroutine> \n typedef std::suspend_never blub; \nint main() {} " _CXX_COROUTINES_FINAL_HEADER_COMPILES)
161+
if(NOT _CXX_COROUTINES_FINAL_HEADER_COMPILES)
162+
set(_CXX_COROUTINES_HAVE_HEADER FALSE)
163+
endif()
160164
mark_as_advanced(_CXX_COROUTINES_HAVE_HEADER)
161165
if(_CXX_COROUTINES_HAVE_HEADER)
162166
# We found the non-experimental header. Don't bother looking for the

include/cppcoro/config.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,17 @@
150150
# define CPPCORO_CPU_CACHE_LINE 64
151151
#endif
152152

153+
#if CPPCORO_COMPILER_MSVC
154+
#if __has_include(<coroutine>)
155+
#include <yvals_core.h>
156+
#ifdef __cpp_lib_coroutine
157+
#define CPPCORO_COROHEADER_FOUND_AND_USABLE
158+
#endif
159+
#endif
160+
#else
161+
#if __has_include(<coroutine>)
162+
#define CPPCORO_COROHEADER_FOUND_AND_USABLE
163+
#endif
164+
#endif
165+
153166
#endif

include/cppcoro/coroutine.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#ifndef CPPCORO_COROUTINE_HPP_INCLUDED
22
#define CPPCORO_COROUTINE_HPP_INCLUDED
33

4-
#if __has_include(<coroutine>)
4+
#include <cppcoro/config.hpp>
55

6-
#include <coroutine>
6+
#ifdef CPPCORO_COROHEADER_FOUND_AND_USABLE
7+
8+
#includue <coroutine>
79

810
namespace cppcoro {
911
using std::coroutine_handle;

0 commit comments

Comments
 (0)