-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy][misc-const-correctness] fix fp when using const array type. #133018
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
HerrCai0907
merged 5 commits into
llvm:main
from
HerrCai0907:132931-clang-tidy-suggests-adding-const-to-arrays-that-are-already-const
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2defc6
[clang-tidy][misc-const-correctness] fix fp when using const array type.
HerrCai0907 166e457
Update clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
HerrCai0907 42466ed
Update clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
HerrCai0907 8352c50
fix with review
HerrCai0907 417b29d
Merge branch '132931-clang-tidy-suggests-adding-const-to-arrays-that-…
HerrCai0907 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1007,3 +1007,11 @@ template <typename T> void f() { | |
x[T{}] = 3; | ||
} | ||
} // namespace gh127776_false_positive | ||
|
||
namespace gh132931_false_positive { | ||
using T = const int; | ||
void valid(int i) { | ||
const int arr0[] = {1, 2, 3}; | ||
T arr1[] = {1, 2, 3}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we get a warning here, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry I see now |
||
} | ||
} // namespace gh132931_false_positive |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On line 86 it appears the author intended to handle "const arrays" in the "pointee check". They are indeed handled correctly if one of the options is true (I don't recall which one). Is there a bug in that check that we should fix instead?
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.
Alternatively we might want to correct/remove the comment
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.
I think the comment means check the constness of pointer and array instead of const pointer and const array
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.
All the tests (including the FP at hand) pass if you remove
unless(arrayType()
from line 87 (as well as the part of the comment), so I think it would be preferable to do that instead of creating aConstArrayType
.