-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【WIP】Fix the clang-tidy checks (little by little) #1656
【WIP】Fix the clang-tidy checks (little by little) #1656
Conversation
… with std::to_string().
-extra-arg=-std=c++17 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the code patch you provided, here are some observations and suggestions:
-
In the
add_custom_target
block, a new-extra-arg
option with-std=c++17
is added both to theclang-tidy
target and theclang-tidy-fix
target. This implies that both targets will use C++17 as a language standard. -
It's generally recommended to have consistent settings throughout a project. If your project uses C++17 as the language standard, it would be better to define this setting in a centralized location rather than duplicating it in multiple places. You can set the C++ standard in the project's CMakeLists.txt file using the
set(CMAKE_CXX_STANDARD 17)
command. -
Make sure that the necessary dependencies, such as
clang
,clang-apply-replacements
, and the required C++17 support, are properly installed and available in the build environment.
Other than these observations, the code patch appears to be fine. It adds the -extra-arg=-std=c++17
option to the clang-tidy
and clang-tidy-fix
targets, which suggests that C++17 syntax is used correctly within the project.
I'm sorry I accidentally deleted the PR before. |
void RedisAppendLenUint64(std::string& str, uint64_t ori, const std::string& prefix) { | ||
RedisAppendLen(str, static_cast<int64_t>(ori), prefix); | ||
} | ||
|
||
void TryAliasChange(std::vector<std::string>* argv); | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the code patch seems to involve improvements and bug fixes. Here are some key findings and suggestions:
-
Header inclusion: The
#include <memory>
directive is moved up to be included before any other headers that rely on it. This is a good practice to ensure proper dependencies are satisfied. -
RedisAppendLenUint64
: A new functionRedisAppendLenUint64
is introduced as an inline function to append a uint64_t length to a string with a given prefix. This addition helps improve code readability and type safety. -
Naming conventions: The function name
CheckArg
in theCmd
class is modified to accept auint64_t
number instead of anint
. This change improves consistency and avoids potential issues when using large numbers of arguments. -
Logging: There doesn't seem to be any particular issue with the
LogCommand
method or its usage. However, without seeing the implementation details, it's challenging to provide specific feedback on its effectiveness or potential areas for improvement. -
Code comments: The provided comments sufficiently explain the purpose and recommended usage of certain functions, such as
AppendStringLenUint64
andAppendArrayLenUint64
. These comments help clarify their intended use, particularly when dealing with large sizes. -
Bug risk assessment: Without a full understanding of the codebase and its context, it's difficult to assess potential bugs or risks. Reviewing the entire codebase and considering test cases would be necessary for a comprehensive assessment.
The code patch primarily introduces improvements related to type safety and readability. It's always a good practice to thoroughly test the changes and consider using static analysis tools to identify any potential issues that might not be apparent from a high-level review.
…function with std::to_string()." due to ctest failed This reverts commit 23ebbe8.
@@ -227,7 +231,7 @@ int CalculateDataStartAndEndKey(const std::string& key, std::string* data_start_ | |||
dst_ptr += sizeof(int32_t); | |||
std::strncpy(dst_ptr, key.data(), key.size()); | |||
dst_ptr += key.size(); | |||
*dst_ptr = static_cast<uint8_t>(0xff); | |||
*dst_ptr = static_cast<char>(0xff); | |||
|
|||
data_start_key->assign(start, sizeof(int32_t) + key.size()); | |||
data_end_key->assign(start, sizeof(int32_t) + key.size() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some observations and suggestions for the code patch:
-
In the function
StringMatchUint64
, it seems you are trying to handle 64-bit unsigned integers (uint64_t
), but the function name and parameter types indicate it should be handling 32-bit signed integers (int
). If you intend to handleuint64_t
, consider updating the function name, parameter names, and types consistently. -
In the function
LongDoubleToStr
, there are two lines commented out wherelen
is assigned the value of either 3 or 4. If these lines are not needed anymore, you can remove them to avoid confusion. -
In the function
CalculateMetaStartAndEndKey
andCalculateDataStartAndEndKey
, casting0xff
tostatic_cast<char>(0xff)
appears unnecessary since0xff
is already within the range ofchar
.
Overall, the code doesn't seem to have major bug risks based on what is shown in the code patch. However, it would be helpful to review the rest of the codebase to ensure the changes made here don't introduce subtle issues. Furthermore, detailed code review would require a deeper understanding of the context and related code.
…g for some header files
-extra-arg=-std=c++17 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code patch you provided seems to remove the -header-filter
option from both the add_custom_target
commands. This option is used to specify a regular expression filter for the files that will be analyzed by clang-tidy. Without the -header-filter
, clang-tidy will analyze all the files in the project directory.
If the removal of the -header-filter
option was intentional and you want to analyze all files, then there are no bug risks per se. However, keep in mind that analyzing all files can significantly increase the analysis time, especially for large projects.
As for improvement suggestions, here are a few:
- Consider keeping the
-header-filter
option or modify it to filter only specific directories or files that you need to analyze. This can help reduce unnecessary analysis and improve performance. - It's generally a good practice to provide a newline at the end of the file to ensure consistency with coding standards.
- Ensure that the paths specified for
${CMAKE_CURRENT_SOURCE_DIR}
and${CMAKE_BINARY_DIR}
are correct and point to the desired locations.
Overall, without more context about your project and the intention behind the code changes, it's difficult to provide specific recommendations. It's always a good idea to thoroughly test the modified code to ensure it behaves as expected.
@@ -267,7 +267,7 @@ class RmNode : public Node { | |||
const std::string& DBName() const { return slot_info_.db_name_; } | |||
uint32_t SlotId() const { return slot_info_.slot_id_; } | |||
const SlotInfo& NodeSlotInfo() const { return slot_info_; } | |||
void SetSessionId(uint32_t session_id) { session_id_ = session_id; } | |||
void SetSessionId(int32_t session_id) { session_id_ = session_id; } | |||
int32_t SessionId() const { return session_id_; } | |||
std::string ToString() const { | |||
return "slot=" + DBName() + "_" + std::to_string(SlotId()) + ",ip_port=" + Ip() + ":" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code patch you provided, here are a few observations and suggestions for improvement:
-
In the definition of
PIKA_TTL_NONE
andPIKA_TTL_STALE
, it is recommended to enclose the values in parentheses for clarity. So instead of#define PIKA_TTL_NONE -1
, you can use#define PIKA_TTL_NONE (-1)
. -
In the
SetSessionId
function of theRmNode
class, the parameter type isint32_t
, but the setter name suggests that it should beuint32_t
instead. If session ids are always positive, consider changing the parameter type touint32_t
as per the getter (SessionId()
). -
In the
ToString()
function of theRmNode
class, string concatenation using the+
operator can be error-prone and less efficient. Consider usingstd::ostringstream
orfmt::format
(if available) for better string formatting and concatenation. -
Ensure that all necessary classes and headers are included in the implementation file if they are not shown in the provided code snippet.
-
It would be helpful to review the surrounding context and other parts of the codebase to provide a more comprehensive code review.
Remember to thoroughly test your code after making any changes to ensure proper functionality and identify any potential bugs.
@@ -27,7 +27,7 @@ | |||
class PikaConf : public pstd::BaseConf { | |||
public: | |||
PikaConf(const std::string& path); | |||
~PikaConf() override {} | |||
~PikaConf() override = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
析构函数也要赋初始值吗,感觉这种没必要吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy 检查项 modernize-use-equals-default 建议使用显式 default 和 delete ,可为编译器优化提供更多可能
|
Fix some of the content according to the suggestions made in the last code review.
And fix the code after rebasing the latest branch.