[PATCH] D33497: [clang-tidy] check for __func__/__FUNCTION__ in lambdas

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 30 05:05:12 PDT 2017


alexfh added inline comments.


================
Comment at: clang-tidy/misc/LambdaFunctionNameCheck.cpp:61-62
+void LambdaFunctionNameCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+  Compiler.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(
+      new MacroExpansionsWithFileAndLine(&SuppressMacroExpansions)));
+}
----------------
`llvm::make_unique<MacroExpansionsWithFileAndLine>(...)`


================
Comment at: clang-tidy/misc/LambdaFunctionNameCheck.cpp:67-68
+  const auto *E = Result.Nodes.getNodeAs<PredefinedExpr>("E");
+  if (E->getIdentType() == PredefinedExpr::Func ||
+      E->getIdentType() == PredefinedExpr::Function) {
+    if (E->getLocation().isMacroID()) {
----------------
nit: I'd use the early return style here.


================
Comment at: clang-tidy/misc/LambdaFunctionNameCheck.cpp:73-74
+      SourceRange AsRange(ER.first, ER.second);
+      for (const auto& R : SuppressMacroExpansions) {
+        if (R == AsRange) {
+          // This is a macro expansion for which we should not warn.
----------------
I'm afraid this can become extremely slow on large files with boilerplate/generated code. Since the code is just looking for exact matches (and not any overlapping ranges, for example), we could replace the vector with a (hash?) map to limit the worst case complexity.


https://reviews.llvm.org/D33497





More information about the cfe-commits mailing list