This patch fixes 'Bug 41120'
https://bugs.llvm.org/show_bug.cgi?id=41120
When clang-tidy encounter a fixup name that would become a keyword, it just display a warning with a reason and doesn't attempt to fix it.
Please let me know if this patch is OK, Thanks.
Details
- Reviewers
alexfh hokein aaron.ballman
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
---|---|---|
865 | Please don't use auto when type is not spelled in same statement or not iterator. | |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h | ||
68 | Does value really matter? | |
99 | Please use default member initialization and = default; |
I logged the original bug and I like it!
I think the warning is better than mutating with a prefix, Thank you.
I'll let the code owners approve it, but you have my vote!
glad to hear it :)
I saw this issue when I submitted mine (https://bugs.llvm.org/show_bug.cgi?id=43306) which for now seems to be a harder fix, still looking for solution there.
I saw this issue when I submitted mine (https://bugs.llvm.org/show_bug.cgi?id=43306) which for now seems to be a harder fix, still looking for a solution there.
oh boy!...are you gonna have to look at every variable/macro in scope and compare?
Don't know yet, I thought about using Sema::CheckShadow or Sema::LookupName, but I can't find a Sema instance, not sure how those methods effect performance
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
---|---|---|
877 | Can this be const IdentifierTable&? | |
880 | What if changing it would switch to using a macro instead of a keyword? e.g., #define foo 12 void func(int Foo); // Changing Foo to foo would be bad, no? | |
951 | Diagnostics are not full sentences, so the full stop and capitalization are wrong here. I think this should be combined with the diagnostic above using a %select. auto Diag = diag(Decl.first, "invalid case style for %0 '%1'%select{; cannot be fixed because '%3' would conflict with a keyword|}2") << Failure.KindName << Decl.second << (Failure.FixStatus != ShouldFixStatus::ConflictsWithKeyword) << Failure.Fixup; | |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h | ||
70 | if -> If | |
73 | Missing a full stop at the end of the comment. | |
99 | This seems a bit confusing to me. It seems like the reason to not generate a fixit is being used to determine whether to diagnose at all, which seems incorrect despite sort of being what the old code did. | |
100 | Drop the parens. | |
clang-tools-extra/test/clang-tidy/readability-identifier-naming-bugfix-name-conflicts.cpp | ||
28 | Please add the newline to the end of the file. | |
clang/include/clang/Basic/IdentifierTable.h | ||
584 | Is this actually needed? Pretty sure you can use std::find(table.begin(), table.end(), Name); at the call site (or something similar). |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
---|---|---|
880 | That's another type of bug, just like the one I found https://bugs.llvm.org/show_bug.cgi?id=43306 | |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h | ||
99 | I`m sorry, I didn't understand you. | |
clang/include/clang/Basic/IdentifierTable.h | ||
584 | Yes, because std::find would be slower here compare to HashTable.find |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
---|---|---|
880 | Regarding your comment about macro name, I can fix it using IdentifierInfo::hasMacroDefinition. |
Added check for macro definition, please re-review the enum ShouldFixStatus as now I use it as a switch-case within the diagnostic message.
Thanks.
LGTM aside from a minor nit.
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | ||
---|---|---|
880 | Thanks for fixing this! | |
881–885 | You can elide the curly braces. | |
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h | ||
99 | I see now that the reason we don't diagnose is because the construct is within a macro, which is a pretty reasonable thing to do, so I'm no longer confused. :-) |
Thank you for the patch! I've commit on your behalf in e477988309dbde214a6d16ec690a416882714aac
Thank you for the commit,
just a little question. shouldn't the test file clang-tools-extra/test/clang-tidy/readability-identifier-naming-bugfix-name-conflicts.cpp be added?
It absolutely should have been, but I don't see why it didn't get added. I've fixed it in 7b6174bb147957b4695023ae57c95ca07af7b917, thank you for bringing it to my attention!
Does value really matter?