Skip to content

Commit

Permalink
correct NINJA_FALLTHROUGH logic
Browse files Browse the repository at this point in the history
previously, the top option was never used as seemingly intended.
GCC >= 7 has __has_cpp_attribute() and thus much of the original
workarounds aren't needed.

use C++11 [[noreturn]]

only very old compilers wouldn't have this attribute.
the previous code was from 11 years ago.
  • Loading branch information
scivision committed Apr 16, 2024
1 parent 4a66995 commit 302dc42
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@
#include <string>
#include <vector>

#ifdef _MSC_VER
#define NORETURN __declspec(noreturn)
#if !defined(__has_cpp_attribute)
# define __has_cpp_attribute(x) 0
#endif

#if __has_cpp_attribute(noreturn)
# define NORETURN [[noreturn]]
#else
#define NORETURN __attribute__((noreturn))
# define NORETURN // nothing for old compilers
#endif

/// Log a fatal message and exit.
NORETURN void Fatal(const char* msg, ...);

// Have a generic fall-through for different versions of C/C++.
#if defined(__cplusplus) && __cplusplus >= 201703L
#define NINJA_FALLTHROUGH [[fallthrough]]
#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__)
#define NINJA_FALLTHROUGH [[clang::fallthrough]]
#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \
__GNUC__ >= 7
#define NINJA_FALLTHROUGH [[gnu::fallthrough]]
#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7
#define NINJA_FALLTHROUGH __attribute__ ((fallthrough))
#else // C++11 on gcc 6, and all other cases
#define NINJA_FALLTHROUGH
#if __has_cpp_attribute(fallthrough)
# define NINJA_FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
# define NINJA_FALLTHROUGH [[clang::fallthrough]]
#else
# define NINJA_FALLTHROUGH // nothing
#endif

/// Log a warning message.
Expand Down

0 comments on commit 302dc42

Please sign in to comment.