Skip to content

Commit

Permalink
config.h: improved and cleaned up some preprocessor checks (#5663)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Nov 15, 2023
1 parent e7f8985 commit d3a8eb1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gui/translationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


// Provide own translations for standard buttons. This (garbage) code is needed to enforce them to appear in .ts files even after "lupdate gui.pro"
static UNUSED void unused()
UNUSED static void unused()
{
Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "OK"))
Q_UNUSED(QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel"))
Expand Down
53 changes: 34 additions & 19 deletions lib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,26 @@
# include <crtdbg.h>
#endif

// compatibility macros
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

#ifndef __has_include
#define __has_include(x) 0
#endif

#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif

#ifndef __has_feature
#define __has_feature(x) 0
#endif

// C++11 noexcept
#if (defined(__GNUC__) && (__GNUC__ >= 5)) \
#if defined(__cpp_noexcept_function_type) || \
(defined(__GNUC__) && (__GNUC__ >= 5)) \
|| defined(__clang__) \
|| defined(__CPPCHECK__)
# define NOEXCEPT noexcept
Expand All @@ -51,25 +69,21 @@
#endif

// C++11 noreturn
#if defined __has_cpp_attribute
# if __has_cpp_attribute (noreturn)
# define NORETURN [[noreturn]]
# endif
#endif
#if !defined(NORETURN)
# if (defined(__GNUC__) && (__GNUC__ >= 5)) \
#if __has_cpp_attribute (noreturn) \
|| (defined(__GNUC__) && (__GNUC__ >= 5)) \
|| defined(__clang__) \
|| defined(__CPPCHECK__)
# define NORETURN [[noreturn]]
# elif defined(__GNUC__)
# define NORETURN __attribute__((noreturn))
# else
# define NORETURN
# endif
# define NORETURN [[noreturn]]
#elif defined(__GNUC__)
# define NORETURN __attribute__((noreturn))
#else
# define NORETURN
#endif

// fallthrough
#if defined(__clang__)
#if __cplusplus >= 201703L && __has_cpp_attribute (fallthrough)
# define FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
# define FALLTHROUGH [[clang::fallthrough]]
#elif (defined(__GNUC__) && (__GNUC__ >= 7))
# define FALLTHROUGH __attribute__((fallthrough))
Expand All @@ -78,7 +92,9 @@
#endif

// unused
#if defined(__GNUC__) \
#if __cplusplus >= 201703L && __has_cpp_attribute (maybe_unused)
# define UNUSED [[maybe_unused]]
#elif defined(__GNUC__) \
|| defined(__clang__) \
|| defined(__CPPCHECK__)
# define UNUSED __attribute__((unused))
Expand All @@ -87,7 +103,8 @@
#endif

// warn_unused
#if (defined(__clang__) && (__clang_major__ >= 15))
#if __has_cpp_attribute (gnu::warn_unused) || \
(defined(__clang__) && (__clang_major__ >= 15))
# define WARN_UNUSED [[gnu::warn_unused]]
#else
# define WARN_UNUSED
Expand All @@ -110,11 +127,9 @@ static const std::string emptyString;
#define nonneg
#endif

#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define ASAN 1
#endif
#endif

#ifndef ASAN
#ifdef __SANITIZE_ADDRESS__
Expand Down
8 changes: 1 addition & 7 deletions lib/sourcelocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
#ifndef sourcelocationH
#define sourcelocationH

#ifndef __has_builtin
#define __has_builtin(x) 0 // Compatibility with non-clang compilers.
#endif

#ifndef __has_include
#define __has_include(x) 0 // Compatibility with non-clang compilers.
#endif
#include "config.h"

#ifdef __CPPCHECK__
#define CPPCHECK_HAS_SOURCE_LOCATION 0
Expand Down

0 comments on commit d3a8eb1

Please sign in to comment.