config.h: improved and cleaned up some preprocessor checks (#5663)

This commit is contained in:
Oliver Stöneberg 2023-11-15 15:31:12 +01:00 committed by GitHub
parent e7f8985173
commit d3a8eb1ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 27 deletions

View File

@ -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"))

View File

@ -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
@ -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))
@ -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))
@ -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
@ -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__

View File

@ -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