Fix MSVC warnings on enum class switches

This commit is contained in:
Corentin Wallez
2017-07-10 20:31:47 -04:00
committed by Corentin Wallez
parent 6fb3aebf0c
commit 96acaef95e
15 changed files with 80 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ void HandleAssertionFailure(const char* file, const char* function, int line, co
// MSVC triggers a warning in /W4 for do {} while(0). SDL worked around this by using
// // (0,0) and points out that it looks like an owl face.
#if defined(_MSC_VER)
#if defined(NXT_COMPILER_MSVC)
#define NXT_ASSERT_LOOP_CONDITION (0,0)
#else
#define NXT_ASSERT_LOOP_CONDITION (0)
@@ -51,10 +51,10 @@ void HandleAssertionFailure(const char* file, const char* function, int line, co
} \
} while(NXT_ASSERT_LOOP_CONDITION)
#else
#if defined(_MSC_VER)
#if defined(NXT_COMPILER_MSVC)
#define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
__assume(condition)
#elif defined(__clang__) && defined(__builtin_assume)
#elif defined(NXT_COMPILER_CLANG) && defined(__builtin_assume)
#define NXT_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
__builtin_assume(condition)
#else
@@ -66,9 +66,14 @@ void HandleAssertionFailure(const char* file, const char* function, int line, co
#endif
#define NXT_ASSERT(condition) NXT_ASSERT_CALLSITE_HELPER(__FILE__, __func__, __LINE__, condition)
#define NXT_UNREACHABLE() \
do { \
NXT_ASSERT(false && "Unreachable code hit"); NXT_BUILTIN_UNREACHABLE(); \
} while(NXT_ASSERT_LOOP_CONDITION)
#if !defined(NXT_SKIP_ASSERT_SHORTHANDS)
#define ASSERT NXT_ASSERT
#define UNREACHABLE NXT_UNREACHABLE
#endif
#endif // COMMON_ASSERT_H_

View File

@@ -16,10 +16,17 @@
#define COMMON_COMPILER_H_
// Defines macros for compiler-specific functionality
// - NXT_COMPILER_[CLANG|GCC|MSVC]: Compiler detection
// - NXT_BREAKPOINT(): Raises an exception and breaks in the debugger
// - NXT_BUILTIN_UNREACHABLE(): Hints the compiler that a code path is unreachable
// Clang and GCC
#ifdef __GNUC__
#if defined(__clang__)
#define NXT_COMPILER_CLANG
#else
#define NXT_COMPILER_GCC
#endif
#if defined(__i386__) || defined(__x86_64__)
#define NXT_BREAKPOINT() __asm__ __volatile__("int $3\n\t")
@@ -27,11 +34,17 @@
#error "Implement BREAKPOINT on your platform"
#endif
#define NXT_BUILTIN_UNREACHABLE() __builtin_unreachable()
// MSVC
#elif defined(_MSC_VER)
#define NXT_COMPILER_MSVC
extern void __cdecl __debugbreak(void);
#define NXT_BREAKPOINT() __debugbreak()
#define NXT_BUILTIN_UNREACHABLE() __assume(false)
#else
#error "Unsupported compiler"
#endif