[PATCH] Initial version of clang-tidy check to use override instead of virual.

Daniel Jasper djasper at google.com
Fri May 16 01:49:46 PDT 2014


================
Comment at: clang-tidy/misc/UseOverride.cpp:96
@@ +95,3 @@
+        InsertLoc = Tokens[Tokens.size() - 2].getLocation();
+      } else if (TokenText.back() == "ABSTRACT") {
+        InsertLoc = Tokens.back().getLocation();
----------------
Alexander Kornienko wrote:
> 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'}>
>   ...
> 
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.

================
Comment at: clang-tidy/misc/UseOverride.cpp:41
@@ +40,3 @@
+
+  // Re-lex the tokens to get precise locations to insert 'override' and remove
+  // 'virtual'.
----------------
Alexander Kornienko wrote:
> Daniel Jasper wrote:
> > Alexander Kornienko wrote:
> > > 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.)
> > 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.
> 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 ;)
Done. Left locally for now, but we can move it and make it public if necessary.

http://reviews.llvm.org/D3688






More information about the cfe-commits mailing list