fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.85k stars 2.51k forks source link

Fix error: cannot use 'try' with exceptions disabled in Win LLVM Clang #4208

Closed sergio-nsk closed 1 month ago

sergio-nsk commented 1 month ago

Fixes #4207.

LLVM Clang on Windows does not define __GNUC__. The preprocessor falls to #elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS with _HAS_EXCEPTIONS 1 defined in vcruntime.h:104.

sergio-nsk commented 1 month ago

Other GCC related macros undefined in LLVM Clang on Windows:

#define __GCC_ASM_FLAG_OUTPUTS__ 1
< #define __GCC_ATOMIC_BOOL_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR_LOCK_FREE 2
< #define __GCC_ATOMIC_INT_LOCK_FREE 2
< #define __GCC_ATOMIC_LLONG_LOCK_FREE 2
< #define __GCC_ATOMIC_LONG_LOCK_FREE 2
< #define __GCC_ATOMIC_POINTER_LOCK_FREE 2
< #define __GCC_ATOMIC_SHORT_LOCK_FREE 2
< #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
< #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
  #define __GCC_CONSTRUCTIVE_SIZE 64
  #define __GCC_DESTRUCTIVE_SIZE 64
< #define __GCC_HAVE_DWARF2_CFI_ASM 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
< #define __GLIBCXX_BITSIZE_INT_N_0 128
< #define __GLIBCXX_TYPE_INT_N_0 __int128
< #define __GNUC_GNU_INLINE__ 1
< #define __GNUC_MINOR__ 2
< #define __GNUC_PATCHLEVEL__ 1
< #define __GNUC__ 4
< #define __GNUG__ 4
< #define __GXX_ABI_VERSION 1002
< #define __GXX_EXPERIMENTAL_CXX0X__ 1
< #define __GXX_RTTI 1
< #define __GXX_WEAK__ 1
#define __INT16_C_SUFFIX__
mwinterb commented 1 month ago

clang-cl seems to define _CPPUNWIND, which is the define that Microsoft lists in their predefined macros documentation.

sergio-nsk commented 1 month ago

@mwinterb You are right, _CPPUNWIND and __cpp_exceptions instead of _HAS_EXCEPTIONS are defined. Which one to use in this change?

Clang uses #if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L. So I make the same check.

vitaut commented 1 month ago

Please apply clang-format.