diff options
| author | Léo Lam <leo@leolam.fr> | 2021-10-15 21:45:27 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2021-10-15 21:51:01 +0200 |
| commit | 7855e5f73b375433135cd9d319fda186023523e9 (patch) | |
| tree | 7e5424f19d66ea2306861eb29163a9e1ef918aaf /Source/Core/Common/Logging | |
| parent | 6bf10e02766b7c3db30797250c0f3f5fae2eb2d4 (diff) | |
Turn MAX_LOGLEVEL into a true constant (and fix self-comparison warning)
This replaces the MAX_LOGLEVEL define with a constexpr variable
in order to fix self-comparison warnings in the logging macros
when compiling with Clang. (Without this change, the log level check
in the logging macros is expanded into something like this:
`if (LINFO <= LINFO)`, which triggers a tautological compare warning.)
Diffstat (limited to 'Source/Core/Common/Logging')
| -rw-r--r-- | Source/Core/Common/Logging/Log.h | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Source/Core/Common/Logging/Log.h b/Source/Core/Common/Logging/Log.h index 154b442290..30098f77ee 100644 --- a/Source/Core/Common/Logging/Log.h +++ b/Source/Core/Common/Logging/Log.h @@ -76,6 +76,12 @@ enum LOG_LEVELS LDEBUG = 5, // Detailed debugging - might make things slow. }; +#if defined(_DEBUG) || defined(DEBUGFAST) +constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LDEBUG; +#else +constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LINFO; +#endif // logging + static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID"; void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, @@ -99,19 +105,11 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con ; } // namespace Common::Log -#if defined(_DEBUG) || defined(DEBUGFAST) -#define MAX_LOGLEVEL Common::Log::LOG_LEVELS::LDEBUG -#else -#ifndef MAX_LOGLEVEL -#define MAX_LOGLEVEL Common::Log::LOG_LEVELS::LINFO -#endif // loglevel -#endif // logging - // Let the compiler optimize this out #define GENERIC_LOG(t, v, ...) \ do \ { \ - if (v <= MAX_LOGLEVEL) \ + if (v <= Common::Log::MAX_LOGLEVEL) \ Common::Log::GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \ } while (0) @@ -146,7 +144,7 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con #define GENERIC_LOG_FMT(t, v, format, ...) \ do \ { \ - if (v <= MAX_LOGLEVEL) \ + if (v <= Common::Log::MAX_LOGLEVEL) \ { \ /* Use a macro-like name to avoid shadowing warnings */ \ constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \ |
