[PATCH] D92756: [clang-tidy] Support all YAML supported spellings for bools in CheckOptions.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 7 05:03:56 PST 2020


njames93 created this revision.
njames93 added a reviewer: aaron.ballman.
Herald added a subscriber: xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D92755 <https://reviews.llvm.org/D92755>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92756

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,9 @@
   <clang-tidy/checks/cppcoreguidelines-init-variables>` and
   :doc:`modernize-make-unique <clang-tidy/checks/modernize-make-unique>`.
 
+- CheckOptions that take boolean values now support all spellings supported in 
+  the `YAML format <https://yaml.org/type/bool.html>`_.
+
 New modules
 ^^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/WithColor.h"
+#include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -101,13 +102,11 @@
 
 static llvm::Expected<bool> getAsBool(StringRef Value,
                                       const llvm::Twine &LookupName) {
-  if (Value == "true")
-    return true;
-  if (Value == "false")
-    return false;
-  bool Result;
-  if (!Value.getAsInteger(10, Result))
-    return Result;
+  // To maintain backwards compatability, we support parsing numbers as
+  // booleans, even though its not supported in YAML.
+  if (llvm::Optional<bool> Parsed =
+          llvm::yaml::parseBool(Value, /*AllowNumeric=*/true))
+    return *Parsed;
   return llvm::make_error<UnparseableIntegerOptionError>(LookupName.str(),
                                                          Value.str(), true);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92756.309883.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201207/ad1e3569/attachment-0001.bin>


More information about the cfe-commits mailing list