Skip to content

Commit c68e308

Browse files
authored
[clang-tidy] fix warning about decaying array to pointer (#1926)
* [clang-tidy] fix warning about decaying array to pointer * fix a different warning (old style cast) * use string_view instead of old-style const char* strings * ensure bazel windows is using c++17 * learn to use bazel * and tests * precommit fix * more string_view creation and casting * format * format * [clang-tidy] use unique_ptr for benchmark registration (#1927) * use unique_ptr for benchmark registration
1 parent 05c5930 commit c68e308

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ COPTS = [
1717
"-Werror=old-style-cast",
1818
]
1919

20+
MSVC_COPTS = [
21+
"/std:c++17",
22+
]
23+
2024
config_setting(
2125
name = "windows",
2226
constraint_values = ["@platforms//os:windows"],
@@ -45,7 +49,7 @@ cc_library(
4549
"include/benchmark/export.h",
4650
],
4751
copts = select({
48-
":windows": [],
52+
":windows": MSVC_COPTS,
4953
"//conditions:default": COPTS,
5054
}),
5155
defines = [

include/benchmark/benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ class Fixture : public internal::Benchmark {
16121612
#define BENCHMARK_MAIN() \
16131613
int main(int argc, char** argv) { \
16141614
char arg0_default[] = "benchmark"; \
1615-
char* args_default = arg0_default; \
1615+
char* args_default = reinterpret_cast<char*>(arg0_default); \
16161616
if (!argv) { \
16171617
argc = 1; \
16181618
argv = &args_default; \

src/check.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cmath>
55
#include <cstdlib>
66
#include <ostream>
7+
#include <string_view>
78

89
#include "benchmark/export.h"
910
#include "internal_macros.h"
@@ -46,7 +47,8 @@ BENCHMARK_NORETURN inline void CallAbortHandler() {
4647
// destructed.
4748
class CheckHandler {
4849
public:
49-
CheckHandler(const char* check, const char* file, const char* func, int line)
50+
CheckHandler(std::string_view check, std::string_view file,
51+
std::string_view func, int line)
5052
: log_(GetErrorLogInstance()) {
5153
log_ << file << ":" << line << ": " << func << ": Check `" << check
5254
<< "' failed. ";
@@ -80,9 +82,11 @@ class CheckHandler {
8082
// The BM_CHECK macro returns a std::ostream object that can have extra
8183
// information written to it.
8284
#ifndef NDEBUG
83-
#define BM_CHECK(b) \
84-
(b ? ::benchmark::internal::GetNullLogInstance() \
85-
: ::benchmark::internal::CheckHandler(#b, __FILE__, __func__, __LINE__) \
85+
#define BM_CHECK(b) \
86+
(b ? ::benchmark::internal::GetNullLogInstance() \
87+
: ::benchmark::internal::CheckHandler( \
88+
std::string_view(#b), std::string_view(__FILE__), \
89+
std::string_view(__func__), __LINE__) \
8690
.GetLog())
8791
#else
8892
#define BM_CHECK(b) ::benchmark::internal::GetNullLogInstance()

test/BUILD

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ TEST_COPTS = [
2424
"-Werror=old-style-cast",
2525
]
2626

27+
TEST_MSVC_OPTS = [
28+
"/std:c++17",
29+
]
30+
2731
# Some of the issues with DoNotOptimize only occur when optimization is enabled
2832
PER_SRC_COPTS = {
2933
"donotoptimize_test.cc": ["-O3"],
@@ -45,7 +49,7 @@ cc_library(
4549
srcs = ["output_test_helper.cc"],
4650
hdrs = ["output_test.h"],
4751
copts = select({
48-
"//:windows": [],
52+
"//:windows": TEST_MSVC_OPTS,
4953
"//conditions:default": TEST_COPTS,
5054
}),
5155
deps = [
@@ -61,7 +65,7 @@ cc_library(
6165
size = "small",
6266
srcs = [test_src],
6367
copts = select({
64-
"//:windows": [],
68+
"//:windows": TEST_MSVC_OPTS,
6569
"//conditions:default": TEST_COPTS,
6670
}) + PER_SRC_COPTS.get(test_src, []),
6771
deps = [
@@ -82,7 +86,7 @@ cc_library(
8286
srcs = [test_src],
8387
args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []),
8488
copts = select({
85-
"//:windows": [],
89+
"//:windows": TEST_MSVC_OPTS,
8690
"//conditions:default": TEST_COPTS,
8791
}) + PER_SRC_COPTS.get(test_src, []),
8892
deps = [
@@ -108,7 +112,7 @@ cc_test(
108112
size = "small",
109113
srcs = ["link_main_test.cc"],
110114
copts = select({
111-
"//:windows": [],
115+
"//:windows": TEST_MSVC_OPTS,
112116
"//conditions:default": TEST_COPTS,
113117
}),
114118
deps = ["//:benchmark_main"],

0 commit comments

Comments
 (0)