Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COPTS = [
"-Wshadow",
# "-Wshorten-64-to-32",
"-Wfloat-equal",
"-Wformat=2",
"-fstrict-aliasing",
## assert() are used a lot in tests upstream, which may be optimised out leading to
## unused-variable warning.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ else()
add_cxx_compiler_flag(-Wfloat-equal)
add_cxx_compiler_flag(-Wold-style-cast)
add_cxx_compiler_flag(-Wconversion)
add_cxx_compiler_flag(-Wformat=2)
if(BENCHMARK_ENABLE_WERROR)
add_cxx_compiler_flag(-Werror)
endif()
Expand Down
12 changes: 2 additions & 10 deletions src/colorprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <iostream>
#include <string>

#include "internal_macros.h"

namespace benchmark {
enum LogColor {
COLOR_DEFAULT,
Expand All @@ -17,16 +19,6 @@ enum LogColor {
COLOR_WHITE
};

#if defined(__GNUC__) || defined(__clang__)
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx) \
__attribute__((format(printf, format_arg, first_idx)))
#elif defined(__MINGW32__)
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx) \
__attribute__((format(__MINGW_PRINTF_FORMAT, format_arg, first_idx)))
#else
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx)
#endif

PRINTF_FORMAT_STRING_FUNC(1, 0)
std::string FormatString(const char* msg, va_list args);
PRINTF_FORMAT_STRING_FUNC(1, 2) std::string FormatString(const char* msg, ...);
Expand Down
1 change: 1 addition & 0 deletions src/console_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void ConsoleReporter::ReportRuns(const std::vector<Run>& reports) {
}
}

PRINTF_FORMAT_STRING_FUNC(3, 4)
static void IgnoreColorPrint(std::ostream& out, LogColor /*unused*/,
const char* fmt, ...) {
va_list args;
Expand Down
10 changes: 10 additions & 0 deletions src/internal_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
#define BENCHMARK_MAYBE_UNUSED
#endif

#if defined(__GNUC__) || defined(__clang__)
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx) \
__attribute__((format(printf, format_arg, first_idx)))
#elif defined(__MINGW32__)
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx) \
__attribute__((format(__MINGW_PRINTF_FORMAT, format_arg, first_idx)))
#else
#define PRINTF_FORMAT_STRING_FUNC(format_arg, first_idx)
#endif

// clang-format on

#endif // BENCHMARK_INTERNAL_MACROS_H_
1 change: 1 addition & 0 deletions src/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ std::string ToBinaryStringFullySpecified(double value, int precision,
return mantissa + ExponentToPrefix(exponent, one_k == Counter::kIs1024);
}

PRINTF_FORMAT_STRING_FUNC(1, 0)
std::string StrFormatImp(const char* msg, va_list args) {
// we might need a second shot at this, so pre-emptivly make a copy
va_list args_cp;
Expand Down
Loading