This is an archive of the discontinued LLVM Phabricator instance.

Initial version of clang-tidy check to use override instead of virual.
ClosedPublic

Authored by djasper on May 9 2014, 2:33 AM.

Details

Summary

I'll add some more tests for members of template classes etc., but I wanted to get some initial feedback.

Diff Detail

Event Timeline

djasper updated this revision to Diff 9240.May 9 2014, 2:33 AM
djasper retitled this revision from to Initial version of clang-tidy check to use override instead of virual..
djasper updated this object.
djasper edited the test plan for this revision. (Show Details)
djasper added reviewers: klimek, alexfh.
djasper added a subscriber: Unknown Object (MLST).
alexfh edited edge metadata.May 9 2014, 3:12 AM

This check (especially the fix part) would be really nice to have.

clang-tidy/misc/UseOverride.cpp
33

Does it make sense to check for getLocation().isMacroID() after this?

42

Can you adapt FindToken from google/GoogleTidyModule.cpp to be usable here (and move it to a common place)? (Or maybe convert it to ParseTokens or something similar.)

test/clang-tidy/use-override.cpp
2

Please add tests with macros: when the whole class is defined in a macro and when a macro is used for "override" and for "virtual" (which is interesting, as the code removes "virtual").

djasper added inline comments.May 15 2014, 2:10 AM
clang-tidy/misc/UseOverride.cpp
33

Changed order of the first two checks.

42

Only partially as I need to lex all the tokens of the function definition (to scan backwards for "= 0"). I guess we could pull out abstraction here, but I am not exactly sure what that should be.

test/clang-tidy/use-override.cpp
2

Done.

djasper updated this revision to Diff 9417.May 15 2014, 2:11 AM
djasper edited edge metadata.

Updated patch.

alexfh added inline comments.May 15 2014, 6:13 AM
clang-tidy/misc/UseOverride.cpp
42

We could at least pull out something like this:

vector<Token> ParseTokens(SourceLocation From, SourceLocation To, <SourceManager and whatever else is needed>);

To be more generic "To" could be replaced by a predicate, though this may be too generic ;)

97

Instead of special-casing this macro, you could find if the identifier is a macro, and see what it expands to using something similar to this:

IdentifierInfo *II = PP.getIdentifierInfo(Token.back());
if (II.hadMacroDefinition()) {
  if (const DefMacroDirective *Def = PP.getMacroDirectiveHistory(II)->findDirectiveAtLoc(...)->getDirective()) {
    <compare Def->getInfo()->tokens_{begin,end}() with {'=', '0'}>
...
djasper added inline comments.May 16 2014, 1:49 AM
clang-tidy/misc/UseOverride.cpp
42

Done. Left locally for now, but we can move it and make it public if necessary.

97

Clang-tidy doesn't have access to the preprocessor. However, I think we'll want to store the corresponding locations explicitly in FunctionDecls. Left FIXME to this effect.

djasper updated this revision to Diff 9465.May 16 2014, 1:50 AM

Address comments and add more tests.

Looks good once you remove " Method->dump();" that you left on line 55.

djasper accepted this revision.May 22 2014, 2:56 AM
djasper added a reviewer: djasper.
This revision is now accepted and ready to land.May 22 2014, 2:56 AM
djasper closed this revision.May 22 2014, 2:56 AM