Skip to content

Commit 701e888

Browse files
authored
fix: fix clang tidy error (#21)
1 parent 4c82276 commit 701e888

27 files changed

+97
-81
lines changed

.github/workflows/clang_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ jobs:
4646
env:
4747
CC: clang
4848
CXX: clang++
49-
run: ci/scripts/build_paimon.sh $(pwd)
49+
run: ci/scripts/build_paimon.sh $(pwd) false true

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ repos:
6969
]
7070

7171
- repo: https://github.com/cpplint/cpplint
72-
rev: 1.6.1
72+
rev: 2.0.2
7373
hooks:
7474
- id: cpplint
7575
alias: cpp
7676
name: C++ Lint
7777
args:
7878
- "--quiet"
7979
- "--verbose=2"
80-
- "--filter=-whitespace/line_length,-whitespace/parens,-build/c++11,-readability/nolint,-runtime/references"
80+
- "--filter=-whitespace/line_length,-whitespace/parens,-whitespace/indent_namespace,-build/include_what_you_use,-build/c++11,-build/c++17,-readability/nolint,-runtime/references"
8181

8282
types_or:
8383
- c++

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ if(PAIMON_LINT_GIT_DIFF_MODE)
118118
set(GIT_DIFF_FILE_PATH ${CMAKE_BINARY_DIR}/git_diff_files.txt)
119119
add_custom_target(update_diff_files
120120
# get git-diff file list
121-
COMMAND git diff-index --name-only --diff-filter=a --cached
121+
COMMAND git diff-index --name-only --diff-filter=d --cached
122122
${PAIMON_LINT_GIT_TARGET_COMMIT} > ${GIT_DIFF_FILE_PATH}
123123
# convert to absolute path
124124
COMMAND sed -i \"s|^|${CMAKE_SOURCE_DIR}/|\" ${GIT_DIFF_FILE_PATH}

ci/scripts/build_paimon.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set -eux
1818

1919
source_dir=${1}
2020
enable_sanitizer=${2:-false}
21+
check_clang_tidy=${3:-false}
2122
build_dir=${1}/build
2223

2324
mkdir ${build_dir}
@@ -42,6 +43,10 @@ cmake "${CMAKE_ARGS[@]}" ${source_dir}
4243
cmake --build . -- -j$(nproc)
4344
ctest --output-on-failure -j $(nproc)
4445

46+
if [[ "${check_clang_tidy}" == "true" ]]; then
47+
cmake --build . --target check-clang-tidy
48+
fi
49+
4550
popd
4651

4752
rm -rf ${build_dir}

include/paimon/result.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ class PAIMON_MUST_USE_TYPE PAIMON_EXPORT Result {
3737
status_.~Status();
3838
}
3939

40+
// NOLINTBEGIN(google-explicit-constructor, runtime/explicit)
4041
/// Construct a successful result with a copy of the given value.
4142
/// @param data The value to store in result.
42-
Result(const T& data) : status_(), data_(data) {} // NOLINT(runtime/explicit)
43+
Result(const T& data) : status_(), data_(data) {}
4344

4445
/// Construct a successful result by moving the given value.
4546
/// @param data The value to move into result.
46-
Result(T&& data) : status_(), data_(std::move(data)) {} // NOLINT(runtime/explicit)
47+
Result(T&& data) : status_(), data_(std::move(data)) {}
4748

4849
/// Template constructor for converting compatible pointer types.
4950
/// Support T = std::unique_ptr<B> and U = std::unique_ptr<D> convert, where D is derived class
@@ -53,11 +54,12 @@ class PAIMON_MUST_USE_TYPE PAIMON_EXPORT Result {
5354
std::enable_if_t<
5455
is_pointer<U>::value && is_pointer<T>::value &&
5556
std::is_convertible_v<value_type_traits_t<U>, value_type_traits_t<T>>>* = nullptr>
56-
Result(U&& data) : status_(), data_(std::move(data)) {} // NOLINT(runtime/explicit)
57+
Result(U&& data) : status_(), data_(std::move(data)) {}
5758

5859
/// Construct a failed result with the given status.
5960
/// @param status The status object describing the error.
60-
Result(const Status& status) : status_(status) {} // NOLINT(runtime/explicit)
61+
Result(const Status& status) : status_(status) {}
62+
// NOLINTEND(google-explicit-constructor, runtime/explicit)
6163

6264
/// Copy constructor.
6365
/// @param other The result to copy from.
@@ -79,20 +81,22 @@ class PAIMON_MUST_USE_TYPE PAIMON_EXPORT Result {
7981
MakeStatus(other.status_);
8082
}
8183

84+
// NOLINTBEGIN(google-explicit-constructor, runtime/explicit)
8285
/// Template move constructor for converting compatible `Result` types.
8386
/// @param other The result to move from.
8487
template <typename U,
8588
std::enable_if_t<
8689
is_pointer<U>::value && is_pointer<T>::value &&
8790
std::is_convertible_v<value_type_traits_t<U>, value_type_traits_t<T>>>* = nullptr>
88-
Result(Result<U>&& other) noexcept { // NOLINT(runtime/explicit)
91+
Result(Result<U>&& other) noexcept {
8992
if (other.ok()) {
9093
MakeValue(std::move(other).value());
9194
}
9295
// If we moved the status, the other status may become ok but the other
9396
// value hasn't been constructed => crash on other destructor.
9497
MakeStatus(other.status());
9598
}
99+
// NOLINTEND(google-explicit-constructor, runtime/explicit)
96100

97101
/// Copy assignment operator.
98102
/// @param other The result to copy from.

src/paimon/common/data/binary_row_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TEST_F(BinaryRowTest, TestBasic) {
7474
row.SetInt(0, 5);
7575
row.SetDouble(1, 5.8);
7676
ASSERT_EQ(5, row.GetInt(0));
77-
ASSERT_EQ((double)5.8, row.GetDouble(1));
77+
ASSERT_EQ(static_cast<double>(5.8), row.GetDouble(1));
7878

7979
row.Clear();
8080
std::shared_ptr<Bytes> bytes1 = Bytes::AllocateBytes(100, pool.get());
@@ -405,10 +405,10 @@ TEST_F(BinaryRowTest, TestCompatibleWithJava) {
405405
int32_t arity = 1;
406406
BinaryRow row(arity);
407407
BinaryRowWriter writer(&row, 0, pool.get());
408-
writer.WriteInt(0, static_cast<int32_t>(18));
408+
writer.WriteInt(0, 18);
409409
writer.Complete();
410410

411-
ASSERT_EQ(row.GetInt(0), (int32_t)18);
411+
ASSERT_EQ(row.GetInt(0), 18);
412412

413413
auto bytes = SerializationUtils::SerializeBinaryRow(row, pool.get());
414414
std::string bytes_view(bytes->data(), bytes->size());
@@ -418,7 +418,7 @@ TEST_F(BinaryRowTest, TestCompatibleWithJava) {
418418
ASSERT_EQ(bytes_view, expect_view);
419419
ASSERT_OK_AND_ASSIGN(auto de_row, SerializationUtils::DeserializeBinaryRow(bytes));
420420
ASSERT_EQ(1, de_row.GetFieldCount());
421-
ASSERT_EQ(de_row.GetInt(0), (int32_t)18);
421+
ASSERT_EQ(de_row.GetInt(0), 18);
422422
}
423423
}
424424

@@ -564,8 +564,8 @@ TEST_F(BinaryRowTest, TestBinaryRowSerializer) {
564564
test_string1.reserve(str_size);
565565
test_string2.reserve(str_size);
566566
for (int32_t j = 0; j < str_size; j++) {
567-
test_string1 += paimon::test::RandomNumber(0, 25) + 'a';
568-
test_string2 += paimon::test::RandomNumber(0, 25) + 'a';
567+
test_string1 += static_cast<char>(paimon::test::RandomNumber(0, 25) + 'a');
568+
test_string2 += static_cast<char>(paimon::test::RandomNumber(0, 25) + 'a');
569569
}
570570
std::shared_ptr<Bytes> bytes1 = Bytes::AllocateBytes(test_string1, pool.get());
571571
std::shared_ptr<Bytes> bytes2 = Bytes::AllocateBytes(test_string2, pool.get());

src/paimon/common/data/generic_row_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ TEST(GenericRowTest, TestSimple) {
7878
// test get
7979
ASSERT_FALSE(row.IsNullAt(0));
8080
ASSERT_EQ(row.GetBoolean(0), true);
81-
ASSERT_EQ(row.GetByte(1), (char)1);
82-
ASSERT_EQ(row.GetShort(2), (int16_t)2);
83-
ASSERT_EQ(row.GetInt(3), (int32_t)3);
84-
ASSERT_EQ(row.GetDate(3), (int32_t)3);
85-
ASSERT_EQ(row.GetLong(4), (int64_t)4);
86-
ASSERT_EQ(row.GetFloat(5), (float)5.1);
87-
ASSERT_EQ(row.GetDouble(6), (double)6.12);
81+
ASSERT_EQ(row.GetByte(1), static_cast<char>(1));
82+
ASSERT_EQ(row.GetShort(2), static_cast<int16_t>(2));
83+
ASSERT_EQ(row.GetInt(3), static_cast<int32_t>(3));
84+
ASSERT_EQ(row.GetDate(3), static_cast<int32_t>(3));
85+
ASSERT_EQ(row.GetLong(4), static_cast<int64_t>(4));
86+
ASSERT_EQ(row.GetFloat(5), static_cast<float>(5.1));
87+
ASSERT_EQ(row.GetDouble(6), static_cast<double>(6.12));
8888
ASSERT_EQ(row.GetString(7), str);
8989
ASSERT_EQ(*row.GetBinary(8), *bytes);
9090
ASSERT_EQ(std::string(row.GetStringView(9)), str9);

src/paimon/common/data/record_batch_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TEST(RecordBatchTest, TestSimple) {
5858
ASSERT_TRUE(struct_builder.Append().ok());
5959
ASSERT_TRUE(string_builder->Append("20240813").ok());
6060
ASSERT_TRUE(int_builder->Append(23).ok());
61-
ASSERT_TRUE(long_builder->Append((int64_t)1722848484308ll + i).ok());
61+
ASSERT_TRUE(long_builder->Append(static_cast<int64_t>(1722848484308ll + i)).ok());
6262
ASSERT_TRUE(bool_builder->Append(static_cast<bool>(i % 2)).ok());
6363
}
6464
std::shared_ptr<arrow::Array> array;

src/paimon/common/file_index/file_index_format_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ TEST_F(FileIndexFormatTest, TestSimple) {
149149
}
150150
}
151151

152+
// NOLINTNEXTLINE(google-readability-function-size)
152153
TEST_F(FileIndexFormatTest, TestBitmapIndexWithTimestamp) {
153154
auto schema = arrow::schema({
154155
arrow::field("ts_sec", arrow::timestamp(arrow::TimeUnit::SECOND)),

src/paimon/common/memory/memory_segment.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ class PAIMON_EXPORT MemorySegment {
7373
template <typename T>
7474
inline void Get(int32_t index, T* dst, int32_t offset, int32_t length) const {
7575
// check the byte array offset and length and the status
76-
assert((int32_t)dst->size() >= (offset + length));
77-
assert((int32_t)heap_memory_->size() >= (index + length));
76+
assert(static_cast<int32_t>(dst->size()) >= (offset + length));
77+
assert(static_cast<int32_t>(heap_memory_->size()) >= (index + length));
7878
std::memcpy(const_cast<char*>(dst->data()) + offset, heap_memory_->data() + index, length);
7979
}
8080

8181
template <typename T>
8282
inline void Put(int32_t index, const T& src, int32_t offset, int32_t length) {
8383
// check the byte array offset and length
84-
assert((int32_t)src.size() >= (offset + length));
85-
assert((int32_t)heap_memory_->size() >= (index + length));
84+
assert(static_cast<int32_t>(src.size()) >= (offset + length));
85+
assert(static_cast<int32_t>(heap_memory_->size()) >= (index + length));
8686
std::memcpy(heap_memory_->data() + index, src.data() + offset, length);
8787
}
8888

0 commit comments

Comments
 (0)