Skip to content

Commit b0a5ce7

Browse files
Enable clang-tidy for programs and utils
1 parent 073dc2e commit b0a5ce7

File tree

13 files changed

+48
-43
lines changed

13 files changed

+48
-43
lines changed

.clang-tidy

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Checks: '-*,
99
misc-unused-alias-decls,
1010
misc-unused-parameters,
1111
misc-unused-using-decls,
12-
12+
1313
modernize-avoid-bind,
1414
modernize-loop-convert,
1515
modernize-make-shared,
@@ -33,7 +33,7 @@ Checks: '-*,
3333
performance-no-automatic-move,
3434
performance-trivially-destructible,
3535
performance-unnecessary-copy-initialization,
36-
36+
3737
readability-avoid-const-params-in-decls,
3838
readability-const-return-type,
3939
readability-container-size-empty,
@@ -58,7 +58,7 @@ Checks: '-*,
5858
readability-simplify-boolean-expr,
5959
readability-inconsistent-declaration-parameter-name,
6060
readability-identifier-naming,
61-
61+
6262
bugprone-undelegated-constructor,
6363
bugprone-argument-comment,
6464
bugprone-bad-signal-to-kill-thread,
@@ -102,7 +102,7 @@ Checks: '-*,
102102
bugprone-unused-return-value,
103103
bugprone-use-after-move,
104104
bugprone-virtual-near-miss,
105-
105+
106106
cert-dcl21-cpp,
107107
cert-dcl50-cpp,
108108
cert-env33-c,
@@ -112,7 +112,7 @@ Checks: '-*,
112112
cert-mem57-cpp,
113113
cert-msc50-cpp,
114114
cert-oop58-cpp,
115-
115+
116116
google-build-explicit-make-pair,
117117
google-build-namespaces,
118118
google-default-arguments,
@@ -121,9 +121,9 @@ Checks: '-*,
121121
google-readability-avoid-underscore-in-googletest-name,
122122
google-runtime-int,
123123
google-runtime-operator,
124-
124+
125125
hicpp-exception-baseclass,
126-
126+
127127
clang-analyzer-core.CallAndMessage,
128128
clang-analyzer-core.DivideZero,
129129
clang-analyzer-core.NonNullParamChecker,

programs/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (USE_CLANG_TIDY)
2+
set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
3+
endif ()
4+
15
# 'clickhouse' binary is a multi purpose tool,
26
# that contain multiple execution modes (client, server, etc.)
37
# each of them is built and linked as a separate library, defined below.

programs/odbc-bridge/ODBCBlockOutputStream.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace
2424
query.table_id.table_name = table_name;
2525
query.columns = std::make_shared<ASTExpressionList>(',');
2626
query.children.push_back(query.columns);
27-
for (size_t i = 0; i < columns.size(); ++i)
28-
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(columns[i].name));
27+
for (const auto & column : columns)
28+
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
2929

3030
std::stringstream ss;
3131
IAST::FormatSettings settings(ss, true);

src/Common/tests/cow_columns.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ int main(int, char **)
5656
MutableColumnPtr mut = IColumn::mutate(std::move(y));
5757
mut->set(2);
5858

59-
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
60-
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
59+
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
60+
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
6161
y = std::move(mut);
6262
}
6363

@@ -75,8 +75,8 @@ int main(int, char **)
7575
MutableColumnPtr mut = IColumn::mutate(std::move(y));
7676
mut->set(3);
7777

78-
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
79-
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
78+
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
79+
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
8080
y = std::move(mut);
8181
}
8282

src/Common/tests/cow_compositions.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ int main(int, char **)
7575
MutableColumnPtr mut = IColumn::mutate(std::move(y));
7676
mut->set(2);
7777

78-
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
79-
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
78+
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
79+
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
8080
y = std::move(mut);
8181
}
8282

@@ -94,8 +94,8 @@ int main(int, char **)
9494
MutableColumnPtr mut = IColumn::mutate(std::move(y));
9595
mut->set(3);
9696

97-
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
98-
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
97+
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
98+
std::cerr << "addresses: " << x.get() << ", " << ", " << mut.get() << "\n";
9999
y = std::move(mut);
100100
}
101101

utils/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (USE_CLANG_TIDY)
2+
set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
3+
endif ()
4+
15
if(MAKE_STATIC_LIBRARIES)
26
set(MAX_LINKER_MEMORY 3500)
37
else()

utils/convert-month-partitioned-parts/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void run(String part_path, String date_column, String dest_path)
3030
{
3131
std::shared_ptr<IDisk> disk = std::make_shared<DiskLocal>("local", "/", 0);
3232
auto old_part_path = Poco::Path::forDirectory(part_path);
33-
String old_part_name = old_part_path.directory(old_part_path.depth() - 1);
33+
const String & old_part_name = old_part_path.directory(old_part_path.depth() - 1);
3434
String old_part_path_str = old_part_path.toString();
3535

3636
auto part_info = MergeTreePartInfo::fromPartName(old_part_name, MergeTreeDataFormatVersion(0));

utils/iotest/iotest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
5959

6060
for (size_t i = 0; i < count; ++i)
6161
{
62-
long rand_result1 = rng();
63-
long rand_result2 = rng();
64-
long rand_result3 = rng();
62+
uint64_t rand_result1 = rng();
63+
uint64_t rand_result2 = rng();
64+
uint64_t rand_result3 = rng();
6565

6666
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
6767
size_t offset;
@@ -152,7 +152,7 @@ int mainImpl(int argc, char ** argv)
152152
Stopwatch watch;
153153

154154
for (size_t i = 0; i < threads; ++i)
155-
pool.scheduleOrThrowOnError(std::bind(thread, fd, mode, min_offset, max_offset, block_size, count));
155+
pool.scheduleOrThrowOnError([=]{ thread(fd, mode, min_offset, max_offset, block_size, count); });
156156
pool.wait();
157157

158158
fsync(fd);

utils/iotest/iotest_aio.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ int main(int, char **) { return 0; }
1313
#include <Common/Exception.h>
1414
#include <Common/ThreadPool.h>
1515
#include <Common/Stopwatch.h>
16+
#include <Common/randomSeed.h>
17+
#include <pcg_random.hpp>
1618
#include <IO/BufferWithOwnMemory.h>
1719
#include <IO/ReadHelpers.h>
1820
#include <stdio.h>
@@ -52,10 +54,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
5254
for (size_t i = 0; i < buffers_count; ++i)
5355
buffers[i] = Memory<>(block_size, sysconf(_SC_PAGESIZE));
5456

55-
drand48_data rand_data;
56-
timespec times;
57-
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &times);
58-
srand48_r(times.tv_nsec, &rand_data);
57+
pcg64_fast rng(randomSeed());
5958

6059
size_t in_progress = 0;
6160
size_t blocks_sent = 0;
@@ -82,12 +81,9 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
8281

8382
char * buf = buffers[i].data();
8483

85-
long rand_result1 = 0;
86-
long rand_result2 = 0;
87-
long rand_result3 = 0;
88-
lrand48_r(&rand_data, &rand_result1);
89-
lrand48_r(&rand_data, &rand_result2);
90-
lrand48_r(&rand_data, &rand_result3);
84+
uint64_t rand_result1 = rng();
85+
uint64_t rand_result2 = rng();
86+
uint64_t rand_result3 = rng();
9187

9288
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
9389
size_t offset = min_offset + rand_result % ((max_offset - min_offset) / block_size) * block_size;
@@ -172,7 +168,7 @@ int mainImpl(int argc, char ** argv)
172168
Stopwatch watch;
173169

174170
for (size_t i = 0; i < threads_count; ++i)
175-
pool.scheduleOrThrowOnError(std::bind(thread, fd, mode, min_offset, max_offset, block_size, buffers_count, count));
171+
pool.scheduleOrThrowOnError([=]{ thread(fd, mode, min_offset, max_offset, block_size, buffers_count, count); });
176172
pool.wait();
177173

178174
watch.stop();

utils/iotest/iotest_nonblock.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ int mainImpl(int argc, char ** argv)
113113
polls[i].revents = 0;
114114
++ops;
115115

116-
long rand_result1 = rng();
117-
long rand_result2 = rng();
118-
long rand_result3 = rng();
116+
uint64_t rand_result1 = rng();
117+
uint64_t rand_result2 = rng();
118+
uint64_t rand_result3 = rng();
119119

120120
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
121121
size_t offset;

utils/test-data-generator/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Disable clang-tidy for protobuf generated files
2+
set (CMAKE_CXX_CLANG_TIDY "")
3+
14
add_compile_options(-Wno-zero-as-null-pointer-constant -Wno-array-bounds) # Protobuf generated files
25

36
if (USE_PROTOBUF)

utils/zookeeper-adjust-block-numbers-to-parts/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ std::unordered_map<std::string, Int64> getPartitionsNeedAdjustingBlockNumbers(
102102
std::cout << "Shard: " << shard << std::endl;
103103
std::vector<std::string> use_tables = tables.empty() ? getAllTables(zk, root, shard) : removeNotExistingTables(zk, root, shard, tables);
104104

105-
for (auto table : use_tables)
105+
for (const auto & table : use_tables)
106106
{
107107
std::cout << "\tTable: " << table << std::endl;
108108
std::string table_path = root + "/" + shard + "/" + table;
@@ -121,7 +121,7 @@ std::unordered_map<std::string, Int64> getPartitionsNeedAdjustingBlockNumbers(
121121
continue;
122122
}
123123

124-
for (auto partition : partitions)
124+
for (const auto & partition : partitions)
125125
{
126126
try
127127
{

utils/zookeeper-cli/zookeeper-cli.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ int main(int argc, char ** argv)
9797
bool watch = w == "w";
9898
zkutil::EventPtr event = watch ? std::make_shared<Poco::Event>() : nullptr;
9999
std::vector<std::string> v = zk.getChildren(path, nullptr, event);
100-
for (size_t i = 0; i < v.size(); ++i)
101-
{
102-
std::cout << v[i] << std::endl;
103-
}
100+
for (const auto & child : v)
101+
std::cout << child << std::endl;
104102
if (watch)
105103
waitForWatch(event);
106104
}
@@ -193,7 +191,7 @@ int main(int argc, char ** argv)
193191
zk.set(path, data, version, &stat);
194192
printStat(stat);
195193
}
196-
else if (cmd != "")
194+
else if (!cmd.empty())
197195
{
198196
std::cout << "commands:\n";
199197
std::cout << " q\n";

0 commit comments

Comments
 (0)