[PATCH] D62412: [LibTooling] Fix unused-variable warning after r361647.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 24 11:06:56 PDT 2019


ymandel created this revision.
ymandel added a reviewer: ilya-biryukov.
Herald added a project: clang.

A range-for was added in r361647 where the range variable was only used in an
assertion.  As a result, it warned for Release builds. This revision
restructures the assertion to avoid the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62412

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -7,21 +7,23 @@
 //===----------------------------------------------------------------------===//
 
 #include "TransformerClangTidyCheck.h"
+#include <algorithm>
 
 namespace clang {
 namespace tidy {
 namespace utils {
 using tooling::RewriteRule;
 
-TransformerClangTidyCheck::TransformerClangTidyCheck(tooling::RewriteRule R,
+TransformerClangTidyCheck::TransformerClangTidyCheck(RewriteRule R,
                                                      StringRef Name,
                                                      ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context), Rule(std::move(R)) {
-  for (const auto &Case : Rule.Cases) {
-    assert(Case.Explanation != nullptr &&
-           "clang-tidy checks must have an explanation by default;"
-           " explicitly provide an empty explanation if none is desired");
-  }
+  assert(std::all_of(Rule.Cases.begin(), Rule.Cases.end(),
+                     [](const RewriteRule::Case &C) {
+                       return C.Explanation != nullptr;
+                     }) &&
+         "clang-tidy checks must have an explanation by default;"
+         " explicitly provide an empty explanation if none is desired");
 }
 
 void TransformerClangTidyCheck::registerMatchers(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62412.201289.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190524/448e0ce8/attachment.bin>


More information about the cfe-commits mailing list