diff --git a/.clang-tidy b/.clang-tidy index 732c4aee788..8678cfed1db 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,10 +16,12 @@ Checks: -cert-str34-c, concurrency-*, - + + cppcoreguidelines-narrowing-conversions, cppcoreguidelines-virtual-class-destructor, + cppcoreguidelines-pro-type-cstyle-cast, - google-explicit-constructor + google-explicit-constructor, misc-unused-parameters, diff --git a/src/include/common/arrow/arrow_buffer.h b/src/include/common/arrow/arrow_buffer.h index a273a0454bf..0fbb7593301 100644 --- a/src/include/common/arrow/arrow_buffer.h +++ b/src/include/common/arrow/arrow_buffer.h @@ -66,9 +66,9 @@ struct ArrowBuffer { private: void reserveInternal(uint64_t bytes) { if (dataptr) { - dataptr = (uint8_t*)realloc(dataptr, bytes); + dataptr = static_cast(realloc(dataptr, bytes)); } else { - dataptr = (uint8_t*)malloc(bytes); + dataptr = static_cast(malloc(bytes)); } capacity = bytes; } diff --git a/src/include/common/types/cast_helpers.h b/src/include/common/types/cast_helpers.h index d75289f1c42..24c8972520f 100644 --- a/src/include/common/types/cast_helpers.h +++ b/src/include/common/types/cast_helpers.h @@ -113,7 +113,7 @@ struct DateToStringCast { ptr[0] = '-'; if (date[i] < 10) { ptr[1] = '0'; - ptr[2] = '0' + date[i]; + ptr[2] = static_cast('0' + date[i]); } else { auto index = static_cast(date[i] * 2); ptr[1] = digits[index]; @@ -138,8 +138,8 @@ struct TimeToStringCast { while (endptr > micro_buffer) { *--endptr = '0'; } - uint64_t trailing_zeros = 0; - for (uint64_t i = 5; i > 0; i--) { + int32_t trailing_zeros = 0; + for (int32_t i = 5; i > 0; i--) { if (micro_buffer[i] != '0') { break; } @@ -168,10 +168,10 @@ struct TimeToStringCast { return length; } - static void FormatTwoDigits(char* ptr, int32_t value) { + static void FormatTwoDigits(char* ptr, int64_t value) { if (value < 10) { ptr[0] = '0'; - ptr[1] = '0' + value; + ptr[1] = static_cast('0' + value); } else { auto index = static_cast(value * 2); ptr[0] = digits[index]; diff --git a/src/include/function/schema/label_functions.h b/src/include/function/schema/label_functions.h index 5ddbf445d13..42950ab9185 100644 --- a/src/include/function/schema/label_functions.h +++ b/src/include/function/schema/label_functions.h @@ -6,11 +6,11 @@ namespace kuzu { namespace function { struct Label { - static inline void operation(common::internalID_t& left, common::list_entry_t& right, + static void operation(common::internalID_t& left, common::list_entry_t& right, common::ku_string_t& result, common::ValueVector& leftVector, common::ValueVector& rightVector, common::ValueVector& resultVector, uint64_t resPos) { KU_ASSERT(left.tableID < right.size); - ListExtract::operation(right, left.tableID + 1 /* listExtract requires 1-based index */, + ListExtract::operation(right, left.tableID + 1u /* listExtract requires 1-based index */, result, rightVector, leftVector, resultVector, resPos); } }; diff --git a/src/include/function/string/functions/rpad_function.h b/src/include/function/string/functions/rpad_function.h index 841274bff71..3532c8bb493 100644 --- a/src/include/function/string/functions/rpad_function.h +++ b/src/include/function/string/functions/rpad_function.h @@ -7,8 +7,7 @@ namespace kuzu { namespace function { struct Rpad : BasePadOperation { -public: - static inline void operation(common::ku_string_t& src, int64_t count, + static void operation(common::ku_string_t& src, int64_t count, common::ku_string_t& characterToPad, common::ku_string_t& result, common::ValueVector& resultValueVector) { BasePadOperation::operation(src, count, characterToPad, result, resultValueVector, @@ -18,10 +17,10 @@ struct Rpad : BasePadOperation { static void rpadOperation(common::ku_string_t& src, int64_t count, common::ku_string_t& characterToPad, std::string& paddedResult) { auto srcPadInfo = - BasePadOperation::padCountChars(count, (const char*)src.getData(), src.len); - auto srcData = (const char*)src.getData(); + padCountChars(count, reinterpret_cast(src.getData()), src.len); + auto srcData = reinterpret_cast(src.getData()); paddedResult.insert(paddedResult.end(), srcData, srcData + srcPadInfo.first); - BasePadOperation::insertPadding(count - srcPadInfo.second, characterToPad, paddedResult); + insertPadding(count - srcPadInfo.second, characterToPad, paddedResult); } }; diff --git a/src/include/function/ternary_function_executor.h b/src/include/function/ternary_function_executor.h index a4d0225c044..d8d3bb07595 100644 --- a/src/include/function/ternary_function_executor.h +++ b/src/include/function/ternary_function_executor.h @@ -7,7 +7,7 @@ namespace function { struct TernaryFunctionWrapper { template - static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, + static void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, void* /*aValueVector*/, void* /*resultValueVector*/, void* /*dataPtr*/) { OP::operation(a, b, c, result); } @@ -15,24 +15,24 @@ struct TernaryFunctionWrapper { struct TernaryStringFunctionWrapper { template - static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, + static void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, void* /*aValueVector*/, void* resultValueVector, void* /*dataPtr*/) { - OP::operation(a, b, c, result, *(common::ValueVector*)resultValueVector); + OP::operation(a, b, c, result, *static_cast(resultValueVector)); } }; struct TernaryListFunctionWrapper { template - static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, - void* aValueVector, void* resultValueVector, void* /*dataPtr*/) { - OP::operation(a, b, c, result, *(common::ValueVector*)aValueVector, - *(common::ValueVector*)resultValueVector); + static void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, void* aValueVector, + void* resultValueVector, void* /*dataPtr*/) { + OP::operation(a, b, c, result, *static_cast(aValueVector), + *static_cast(resultValueVector)); } }; struct TernaryUDFFunctionWrapper { template - static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, + static void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result, void* /*aValueVector*/, void* /*resultValueVector*/, void* dataPtr) { OP::operation(a, b, c, result, dataPtr); } @@ -44,10 +44,11 @@ struct TernaryFunctionExecutor { static void executeOnValue(common::ValueVector& a, common::ValueVector& b, common::ValueVector& c, common::ValueVector& result, uint64_t aPos, uint64_t bPos, uint64_t cPos, uint64_t resPos, void* dataPtr) { - auto resValues = (RESULT_TYPE*)result.getData(); + auto resValues = static_cast(result.getData()); OP_WRAPPER::template operation( - ((A_TYPE*)a.getData())[aPos], ((B_TYPE*)b.getData())[bPos], - ((C_TYPE*)c.getData())[cPos], resValues[resPos], (void*)&a, (void*)&result, dataPtr); + static_cast(a.getData())[aPos], static_cast(b.getData())[bPos], + static_cast(c.getData())[cPos], resValues[resPos], static_cast(&a), + static_cast(&result), dataPtr); } template