Skip to content

Commit 865943a

Browse files
[VTR][LOG] Improved Unused Arg Warning Suppression
Previously, VTR's logging used `sizeof` static casted to void in order to suppress the unused argument warning when we want logs to be a NOP. The `sizeof` operator may have some strange affects, but since the code is NOP anyways thats not a huge deal. The reason for this change is that intellisence that use clangd flag this as a potential issue causing warnings. Also moved static variables from the header file of vtr_log to the implementation. No functional change, but just prevents these variables from being present and accessible in every file that uses vtr_log (which is alot).
1 parent 121a16c commit 865943a

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

libs/libvtrutil/src/vtr_log.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <string>
2-
#include <fstream>
31
#include <cstdarg>
2+
#include <fstream>
3+
#include <string>
4+
#include <unordered_set>
45

56
#include "vtr_util.h"
67
#include "vtr_log.h"
@@ -19,6 +20,9 @@ void set_log_file(const char* filename) {
1920

2021
} // namespace vtr
2122

23+
static std::unordered_set<std::string> warnings_to_suppress;
24+
static std::string noisy_warn_log_file;
25+
2226
void add_warnings_to_suppress(std::string function_name) {
2327
warnings_to_suppress.insert(function_name);
2428
}

libs/libvtrutil/src/vtr_log.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef VTR_LOG_H
22
#define VTR_LOG_H
33
#include <tuple>
4-
#include <unordered_set>
54
#include <string>
65

76
/**
@@ -101,19 +100,14 @@
101100
/*
102101
* No-op version of logging macro which avoids unused parameter warnings.
103102
*
104-
* Note that to avoid unused parameter warnings we call sizeof() and cast
105-
* the result to void. sizeof is evaluated at compile time so there is no
106-
* run-time overhead.
107-
*
108-
* Also note the use of std::make_tuple to ensure all arguments in VA_ARGS
109-
* are used.
103+
* Note the use of std::make_tuple to ensure all arguments in VA_ARGS are used.
110104
*/
111105
#define VTR_LOGVF_NOP(expr, file, line, ...) \
112106
do { \
113-
static_cast<void>(sizeof(expr)); \
114-
static_cast<void>(sizeof(file)); \
115-
static_cast<void>(sizeof(line)); \
116-
static_cast<void>(sizeof(std::make_tuple(__VA_ARGS__))); \
107+
static_cast<void>(expr); \
108+
static_cast<void>(file); \
109+
static_cast<void>(line); \
110+
static_cast<void>(std::make_tuple(__VA_ARGS__)); \
117111
} while (false)
118112

119113
// Debug logging macros
@@ -142,9 +136,6 @@ void set_log_file(const char* filename);
142136

143137
} // namespace vtr
144138

145-
static std::unordered_set<std::string> warnings_to_suppress;
146-
static std::string noisy_warn_log_file;
147-
148139
/**
149140
* @brief The following data structure and functions allow to suppress noisy warnings and direct them into an external file, if specified.
150141
*/

0 commit comments

Comments
 (0)