Skip to content

[clang-tidy][NFC]clean ConstCorrectnessCheck #130493

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
return;

VariableCategory VC = VariableCategory::Value;
if (Variable->getType()->isReferenceType())
const QualType VT = Variable->getType();
if (VT->isReferenceType())
VC = VariableCategory::Reference;
if (Variable->getType()->isPointerType())
else if (VT->isPointerType())
VC = VariableCategory::Pointer;
if (Variable->getType()->isArrayType()) {
if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
if (ArrayT->getElementType()->isPointerType())
VC = VariableCategory::Pointer;
}
}
else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this allowed by out current guidelines? This else if blocks contains 2 lines. I think this is rather fragile and can easily break in the future.

Copy link
Contributor

@carlosgalvezp carlosgalvezp Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reading of the guidelines is that we should use braces in the outer if if there is a nested if, like in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be fixed in upstack PR

if (ArrayT->getElementType()->isPointerType())
VC = VariableCategory::Pointer;

// Each variable can only be in one category: Value, Pointer, Reference.
// Analysis can be controlled for every category.
Expand Down
Loading