From e40ac8f6684dbeb4b6a0715baa7b25667b53f1e6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 Apr 2024 17:11:48 -0400 Subject: [PATCH] Fix: cpp-common/bt2c/logging.hpp: add missing `template` keyword In very specific contexts, it's possible that a `bt2c::Logger` reference is a dependent type, for example: template struct X { const bt2c::Logger& logger() const noexcept { return /* some logger reference */; } void log() { BT_CPPLOGI_SPEC(this->logger(), "Hello!"); } }; In that case, the BT_CPPLOGI_SPEC() macro eventually expands to something like: this->logger().log(__FILE__, __func__, __LINE__, "Hello!"); `this->logger()` is basically `X::logger()`. Therefore, from the log() method template point of view, the type of `this` depends on `T`, that is, it's a dependent name. This example above won't build. In that case, we need the `template` keyword to call the method: this->logger().template log(__FILE__, __func__, __LINE__, "Hello!"); Using the `template` keyword or not would normally be a per-call decision, but those BT_CPPLOG*() macros do the call themselves. Knowing this, this patch adds the `template` keyword to all the logging method calls from the BT_CPPLOG*() macros, just in case. The current project builds because it doesn't have this specific situation, but it could happen in the future. Signed-off-by: Philippe Proulx Change-Id: I2847105746825d94cf71ed3abbd56fac0f160a2d Reviewed-on: https://review.lttng.org/c/babeltrace/+/12477 Reviewed-by: Simon Marchi Tested-by: jenkins --- src/cpp-common/bt2c/logging.hpp | 56 ++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/cpp-common/bt2c/logging.hpp b/src/cpp-common/bt2c/logging.hpp index fb21ec4e..90db909b 100644 --- a/src/cpp-common/bt2c/logging.hpp +++ b/src/cpp-common/bt2c/logging.hpp @@ -609,7 +609,8 @@ inline const char *maybeNull(const char * const s) noexcept #define BT_CPPLOG_EX(_lvl, _logger, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).log<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__); \ + (_logger).template log<(_lvl), false>(__FILE__, __func__, __LINE__, (_fmt), \ + ##__VA_ARGS__); \ } \ } while (0) @@ -644,7 +645,7 @@ inline const char *maybeNull(const char * const s) noexcept * Calls logStr() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_STR_EX(_lvl, _logger, _msg) \ - (_logger).logStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_msg)) + (_logger).template logStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_msg)) /* * BT_CPPLOG_STR_EX() with specific logging levels. @@ -679,8 +680,8 @@ inline const char *maybeNull(const char * const s) noexcept #define BT_CPPLOG_MEM_EX(_lvl, _logger, _memData, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).logMem<(_lvl)>(__FILE__, __func__, __LINE__, (_memData), (_fmt), \ - ##__VA_ARGS__); \ + (_logger).template logMem<(_lvl)>(__FILE__, __func__, __LINE__, (_memData), (_fmt), \ + ##__VA_ARGS__); \ } \ } while (0) @@ -721,7 +722,7 @@ inline const char *maybeNull(const char * const s) noexcept * Calls logMemStr() on `_logger` to log using the level `_lvl`. */ #define BT_CPPLOG_MEM_STR_EX(_lvl, _logger, _memData, _msg) \ - (_logger).logMemStr<(_lvl)>(__FILE__, __func__, __LINE__, (_memData), (_msg)) + (_logger).template logMemStr<(_lvl)>(__FILE__, __func__, __LINE__, (_memData), (_msg)) /* * BT_CPPLOG_MEM_STR_EX() with specific logging levels. @@ -763,8 +764,8 @@ inline const char *maybeNull(const char * const s) noexcept #define BT_CPPLOG_ERRNO_EX(_lvl, _logger, _initMsg, _fmt, ...) \ do { \ if (G_UNLIKELY((_logger).wouldLog(_lvl))) { \ - (_logger).logErrno<(_lvl), false>(__FILE__, __func__, __LINE__, (_initMsg), (_fmt), \ - ##__VA_ARGS__); \ + (_logger).template logErrno<(_lvl), false>(__FILE__, __func__, __LINE__, (_initMsg), \ + (_fmt), ##__VA_ARGS__); \ } \ } while (0) @@ -806,7 +807,7 @@ inline const char *maybeNull(const char * const s) noexcept * initial message `_initMsg`. */ #define BT_CPPLOG_ERRNO_STR_EX(_lvl, _logger, _initMsg, _msg) \ - (_logger).logErrnoStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_initMsg), (_msg)) + (_logger).template logErrnoStr<(_lvl), false>(__FILE__, __func__, __LINE__, (_initMsg), (_msg)) /* * BT_CPPLOG_ERRNO_STR_EX() with specific logging levels. @@ -846,8 +847,8 @@ inline const char *maybeNull(const char * const s) noexcept * append a cause to the error of the current thread. */ #define BT_CPPLOGE_APPEND_CAUSE_SPEC(_logger, _fmt, ...) \ - (_logger).log(__FILE__, __func__, __LINE__, (_fmt), \ - ##__VA_ARGS__) + (_logger).template log(__FILE__, __func__, __LINE__, (_fmt), \ + ##__VA_ARGS__) /* * BT_CPPLOGE_APPEND_CAUSE_SPEC() using the default logger. @@ -860,7 +861,8 @@ inline const char *maybeNull(const char * const s) noexcept * append a cause to the error of the current thread. */ #define BT_CPPLOGE_STR_APPEND_CAUSE_SPEC(_logger, _msg) \ - (_logger).logStr(__FILE__, __func__, __LINE__, (_msg)) + (_logger).template logStr(__FILE__, __func__, __LINE__, \ + (_msg)) /* * BT_CPPLOGE_STR_APPEND_CAUSE_SPEC() using the default logger. @@ -874,7 +876,8 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _fmt, ...) \ - (_logger).logErrorAndThrow(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__) + (_logger).template logErrorAndThrow(__FILE__, __func__, __LINE__, (_fmt), \ + ##__VA_ARGS__) /* * BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC() using the default logger. @@ -888,7 +891,7 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _msg) \ - (_logger).logErrorStrAndThrow(__FILE__, __func__, __LINE__, (_msg)) + (_logger).template logErrorStrAndThrow(__FILE__, __func__, __LINE__, (_msg)) /* * BT_CPPLOGE_STR_APPEND_CAUSE_AND_THROW_SPEC() using the default @@ -903,7 +906,7 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _fmt, ...) \ - (_logger).logErrorAndRethrow(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__) + (_logger).template logErrorAndRethrow(__FILE__, __func__, __LINE__, (_fmt), ##__VA_ARGS__) /* * BT_CPPLOGE_APPEND_CAUSE_AND_RETHROW_SPEC() using the default logger. @@ -917,7 +920,7 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _msg) \ - (_logger).logErrorStrAndRethrow(__FILE__, __func__, __LINE__, (_msg)) + (_logger).template logErrorStrAndRethrow(__FILE__, __func__, __LINE__, (_msg)) /* * BT_CPPLOGE_STR_APPEND_CAUSE_AND_RETHROW_SPEC() using the default @@ -931,8 +934,8 @@ inline const char *maybeNull(const char * const s) noexcept * error and append a cause to the error of the current thread. */ #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(_logger, _initMsg, _fmt, ...) \ - (_logger).logErrno(__FILE__, __func__, __LINE__, (_initMsg), \ - (_fmt), ##__VA_ARGS__) + (_logger).template logErrno( \ + __FILE__, __func__, __LINE__, (_initMsg), (_fmt), ##__VA_ARGS__) /* * BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC() using the default logger. @@ -945,8 +948,8 @@ inline const char *maybeNull(const char * const s) noexcept * an error and append a cause to the error of the current thread. */ #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC(_logger, _initMsg, _msg) \ - (_logger).logErrnoStr(__FILE__, __func__, __LINE__, \ - (_initMsg), (_msg)) + (_logger).template logErrnoStr(__FILE__, __func__, __LINE__, \ + (_initMsg), (_msg)) /* * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_SPEC() using the default logger. @@ -960,8 +963,8 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _initMsg, _fmt, ...) \ - (_logger).logErrorErrnoAndThrow(__FILE__, __func__, __LINE__, (_initMsg), \ - (_fmt), ##__VA_ARGS__) + (_logger).template logErrorErrnoAndThrow(__FILE__, __func__, __LINE__, \ + (_initMsg), (_fmt), ##__VA_ARGS__) /* * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_THROW_SPEC() using the default @@ -977,8 +980,8 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW_SPEC(_logger, _excCls, _initMsg, _msg) \ - (_logger).logErrorErrnoStrAndThrow(__FILE__, __func__, __LINE__, (_initMsg), \ - (_msg)) + (_logger).template logErrorErrnoStrAndThrow(__FILE__, __func__, __LINE__, \ + (_initMsg), (_msg)) /* * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_THROW_SPEC() using the default @@ -994,8 +997,8 @@ inline const char *maybeNull(const char * const s) noexcept * `_excCls`. */ #define BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _initMsg, _fmt, ...) \ - (_logger).logErrorErrnoAndRethrow(__FILE__, __func__, __LINE__, (_initMsg), (_fmt), \ - ##__VA_ARGS__) + (_logger).template logErrorErrnoAndRethrow(__FILE__, __func__, __LINE__, (_initMsg), \ + (_fmt), ##__VA_ARGS__) /* * BT_CPPLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_SPEC() using the default @@ -1011,7 +1014,8 @@ inline const char *maybeNull(const char * const s) noexcept * instance of `_excCls`. */ #define BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW_SPEC(_logger, _initMsg, _msg) \ - (_logger).logErrorErrnoStrAndRethrow(__FILE__, __func__, __LINE__, (_initMsg), (_msg)) + (_logger).template logErrorErrnoStrAndRethrow(__FILE__, __func__, __LINE__, (_initMsg), \ + (_msg)) /* * BT_CPPLOGE_ERRNO_STR_APPEND_CAUSE_AND_RETHROW_SPEC() using the -- 2.34.1