Skip to content

Commit 069b131

Browse files
Fix try block enable mechanism (#1185)
* _HAS_EXCEPTION does not represent to cxx-exception * Following is the prove: In file included from D:\a\pltxt2htm\pltxt2htm\cmd\..\include\fast_io/fast_io.h:10: In file included from D:\a\pltxt2htm\pltxt2htm\cmd\..\include\fast_io\fast_io_hosted.h:19: In file included from D:\a\pltxt2htm\pltxt2htm\cmd\..\include\fast_io\fast_io_freestanding.h:23: In file included from D:\a\pltxt2htm\pltxt2htm\cmd\..\include\fast_io\fast_io_freestanding_impl/io_buffer/impl.h:8: D:\a\pltxt2htm\pltxt2htm\cmd\..\include\fast_io\fast_io_freestanding_impl/io_buffer\destroy.h:41:3: error: cannot use 'try' with exceptions disabled 41 | try | ^ Because C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:104:33: note: expanded from macro '_HAS_EXCEPTIONS' 104 | #define _HAS_EXCEPTIONS 1 | ^ * exclude clang when detecting msvc * Add FAST_IO_HAS_EXCEPTIONS macro * fix case `clang --target=unknown-windows-msvc` * handle rtti
1 parent dd3ec8d commit 069b131

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

include/fast_io_dsal/impl/misc/pop_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Please keep it in reverse order with the macros in push_macros.h
22

3+
#pragma pop_macro("FAST_IO_CPP_EXCEPTIONS")
4+
#pragma pop_macro("FAST_IO_CPP_RTTI")
35
#pragma pop_macro("FAST_IO_HAS_BUILTIN")
46
#pragma pop_macro("FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE")
57
#pragma pop_macro("FAST_IO_ASSERT")

include/fast_io_dsal/impl/misc/push_macros.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,27 @@ Internal assert macros for fuzzing fast_io.
224224
#else
225225
# define FAST_IO_HAS_BUILTIN(...) 0
226226
#endif
227+
228+
#pragma push_macro("FAST_IO_CPP_RTTI")
229+
#undef FAST_IO_CPP_RTTI
230+
#if defined(_MSC_VER) && !defined(__clang__)
231+
#if __cpp_rtti >= 199711L && _HAS_RTTI != 0
232+
#define FAST_IO_CPP_RTTI
233+
#endif
234+
#else
235+
#if __cpp_rtti >= 199711L
236+
#define FAST_IO_CPP_RTTI
237+
#endif
238+
#endif
239+
240+
#pragma push_macro("FAST_IO_CPP_EXCEPTIONS")
241+
#undef FAST_IO_CPP_EXCEPTIONS
242+
#if defined(_MSC_VER) && !defined(__clang__)
243+
#if defined(FAST_IO_CPP_RTTI) && __cpp_exceptions >= 199711L && _HAS_EXCEPTIONS != 0
244+
#define FAST_IO_CPP_EXCEPTIONS
245+
#endif
246+
#else
247+
#if defined(FAST_IO_CPP_RTTI) && __cpp_exceptions >= 199711L
248+
#define FAST_IO_CPP_EXCEPTIONS
249+
#endif
250+
#endif

include/fast_io_freestanding_impl/io_buffer/destroy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ inline constexpr void destroy_basic_io_buffer(T &t) noexcept
3737
constexpr auto mode{traits_type::mode};
3838
if constexpr ((mode & buffer_mode::out) == buffer_mode::out)
3939
{
40-
#if (defined(_MSC_VER) && _HAS_EXCEPTIONS != 0) || (!defined(_MSC_VER) && defined(__cpp_exceptions))
40+
#ifdef FAST_IO_CPP_EXCEPTIONS
4141
try
42-
{
4342
#endif
43+
{
4444
::fast_io::details::close_basic_io_buffer(t);
45-
#if (defined(_MSC_VER) && _HAS_EXCEPTIONS != 0) || (!defined(_MSC_VER) && defined(__cpp_exceptions))
4645
}
46+
#ifdef FAST_IO_CPP_EXCEPTIONS
4747
catch (...)
4848
{
4949
}

0 commit comments

Comments
 (0)