This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Reserved-identifier: Improved AllowedIdentifiers option to support regular expressions
ClosedPublic

Authored by felix642 on Jun 12 2023, 5:58 PM.

Diff Detail

Event Timeline

felix642 created this revision.Jun 12 2023, 5:58 PM
felix642 requested review of this revision.Jun 12 2023, 5:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 5:58 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thanks for the patch. This seems like it'll make the check much more useful.

clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
63

Nit: we should AllowedIdentifiersRegex.reserve(AllowedIdentifiers.size()) before the loop.

clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
34

I understand that we need to keep the AllowedIdentifiers member around for use in storeOptions. To avoid confusion, it might make sense to change its name to be the "less default" name (something like AllowedIdentifiersRaw), and give the vector of regexes the more intuitive name AllowedIdentifiers. That would further avoid confusion since getFailureInfoImpl in the .cpp currently refers to the vector of regexes using the name AllowedIdentifiers.

Also, this should probably be const for consistency. The loop in the constructor body should arguably be moved into a helper function anyway, so this member can be initialized in the constructor initializer list.

Except pointed out issues, looks fine.

clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
64–65

avoid double compilation of regexp.
Simply:

AllowedIdentifiersRegex.emplace_back(Identifier.str());
if (!AllowedIdentifiersRegex.back().isValid()) {
       AllowedIdentifiersRegex.pop_back();
    configurationDiag("Invalid allowed identifier regex '%0'") << Identifier;
}
clang-tools-extra/docs/ReleaseNotes.rst
472–474

Sort this entry by full check name.

felix642 updated this revision to Diff 531590.Jun 14 2023, 6:20 PM

Renamed allowedIdentifiers to allowedIdentifiersRaw
Moved regex parsing to a new method
Moved entry in releaseNotes.rst

PiotrZSL accepted this revision.Jun 15 2023, 2:54 PM

Overall looks good..

clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
50

you may remove that last one that is not valid from an AllowedIdentifiers, simply use pop_back()

clang-tools-extra/docs/ReleaseNotes.rst
271

Consider following current approach: "Improved the bugprone-reserved-identifier check by enhancing the AllowedIdentifiers option to support regular expressions."

272

consider inserting here "check"

This revision is now accepted and ready to land.Jun 15 2023, 2:54 PM
felix642 updated this revision to Diff 532495.Jun 18 2023, 6:10 PM

Resolved comments.