[clang-tools-extra] c60ac50 - [clang-tools-extra] Use llvm::to_underlying (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 9 17:34:16 PST 2023


Author: Kazu Hirata
Date: 2023-12-09T17:34:10-08:00
New Revision: c60ac509399da5cba533b9b6cc5b983c59f7d7b3

URL: https://github.com/llvm/llvm-project/commit/c60ac509399da5cba533b9b6cc5b983c59f7d7b3
DIFF: https://github.com/llvm/llvm-project/commit/c60ac509399da5cba533b9b6cc5b983c59f7d7b3.diff

LOG: [clang-tools-extra] Use llvm::to_underlying (NFC)

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
    clang-tools-extra/pseudo/include/clang-pseudo/Token.h

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 831614148c7c2..759cdd44fd658 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -20,6 +20,7 @@
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -167,15 +168,13 @@ static const std::array<const StringRef, 4> Msgs = {{
 // Criteria is a bitset, thus a few helpers are needed.
 CognitiveComplexity::Criteria operator|(CognitiveComplexity::Criteria LHS,
                                         CognitiveComplexity::Criteria RHS) {
-  return static_cast<CognitiveComplexity::Criteria>(
-      static_cast<std::underlying_type_t<CognitiveComplexity::Criteria>>(LHS) |
-      static_cast<std::underlying_type_t<CognitiveComplexity::Criteria>>(RHS));
+  return static_cast<CognitiveComplexity::Criteria>(llvm::to_underlying(LHS) |
+                                                    llvm::to_underlying(RHS));
 }
 CognitiveComplexity::Criteria operator&(CognitiveComplexity::Criteria LHS,
                                         CognitiveComplexity::Criteria RHS) {
-  return static_cast<CognitiveComplexity::Criteria>(
-      static_cast<std::underlying_type_t<CognitiveComplexity::Criteria>>(LHS) &
-      static_cast<std::underlying_type_t<CognitiveComplexity::Criteria>>(RHS));
+  return static_cast<CognitiveComplexity::Criteria>(llvm::to_underlying(LHS) &
+                                                    llvm::to_underlying(RHS));
 }
 CognitiveComplexity::Criteria &operator|=(CognitiveComplexity::Criteria &LHS,
                                           CognitiveComplexity::Criteria RHS) {

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
index 22b72c71cbbab..859fd7d2b3dfe 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -32,6 +32,7 @@
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstdint>
 #include <limits>
@@ -71,10 +72,10 @@ struct Token {
   Index OriginalIndex = Invalid;
   // Helpers to get/set Flags based on `enum class`.
   template <class T> bool flag(T Mask) const {
-    return Flags & uint8_t{static_cast<std::underlying_type_t<T>>(Mask)};
+    return Flags & uint8_t{llvm::to_underlying(Mask)};
   }
   template <class T> void setFlag(T Mask) {
-    Flags |= uint8_t{static_cast<std::underlying_type_t<T>>(Mask)};
+    Flags |= uint8_t{llvm::to_underlying(Mask)};
   }
 
   /// Returns the next token in the stream. this may not be a sentinel.


        


More information about the cfe-commits mailing list