https://godbolt.org/z/n4cK4fo3o
The checker missed a check for invalid vardecl and this could cause a false positive.
Details
Diff Detail
Event Timeline
Looks good in general, IMHO it would be good with a couple more comments to make the code and test easier to understand.
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp | ||
---|---|---|
63 | Add a comment as to why this is needed? I haven't seen this pattern often in checks. | |
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp | ||
4 | Add a comment explaining the purpose of introducing this error? At first sight, it's not obvious to me why this is needed. | |
141 | Perhaps add a comment explaining that clang-tidy should not warn here, and why. |
Now that I think a bit better about this I wonder - does it really make sense that we increase the complexity of the check to cover for cases where code does not compile? If it fails to include a header, there's many other things that can possibly go wrong - should clang-tidy checks in general really be defensive against that? @njames93 WDYT?
It's not a hard rule that we should be defensive against clang-tidy emitting false positives due to a previous compilation error. However for simple cases, like this, where its just ensuring a declaration is valid before we try to emit diagnostic, It does make sense to handle this.
With this change the main thing would be a little less noise while trying to debug the cause of the compilation error which is always a good thing.
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp | ||
---|---|---|
4–13 | All this is unnecessary there is a much nicer way to test this, see below | |
138–140 | This test line is not testing the behaviour described in this patch and can be removed. | |
143 | Just use this and the declaration will be invalid and you can test the expected behaviour |
Just a general workflow comment, can you please mark comments as done when they are addressed, or, if you feel the comment in unjustified, explain why.
@Sockke do you need help landing the patch? If so, let me know user and email for attribution :)
@Sockke ping, can you land this or should we do it for you? If so, please let us know what name and email we should use for attribution.
Add a comment as to why this is needed? I haven't seen this pattern often in checks.