[clang] 108e41d - [clang][NFC] Use c++17 style variable type traits

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 10:25:58 PST 2022


Author: Nathan James
Date: 2022-11-07T18:25:48Z
New Revision: 108e41d962463ea1cb956d1a929692a5b49c0a80

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

LOG: [clang][NFC] Use c++17 style variable type traits

This was done as a test for D137302 and it makes sense to push these changes

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D137491

Added: 
    

Modified: 
    clang/lib/AST/ASTContext.cpp
    clang/lib/AST/ASTImporter.cpp
    clang/lib/AST/Comment.cpp
    clang/lib/AST/Decl.cpp
    clang/lib/AST/Interp/Disasm.cpp
    clang/lib/Analysis/CFG.cpp
    clang/lib/Analysis/RetainSummaryManager.cpp
    clang/lib/Basic/SourceLocation.cpp
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/lib/Lex/MacroArgs.cpp
    clang/lib/Sema/SemaDeclAttr.cpp
    clang/lib/Sema/SemaTemplateDeduction.cpp
    clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
    clang/lib/Tooling/ASTDiff/ASTDiff.cpp
    clang/unittests/Lex/HeaderMapTest.cpp
    clang/unittests/Tooling/ASTSelectionTest.cpp
    clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f07c40cb6c5d..52b361328ebc 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12280,16 +12280,14 @@ static Decl *getCommonDecl(Decl *X, Decl *Y) {
   llvm_unreachable("Corrupt redecls chain");
 }
 
-template <class T,
-          std::enable_if_t<std::is_base_of<Decl, T>::value, bool> = true>
+template <class T, std::enable_if_t<std::is_base_of_v<Decl, T>, bool> = true>
 T *getCommonDecl(T *X, T *Y) {
   return cast_or_null<T>(
       getCommonDecl(const_cast<Decl *>(cast_or_null<Decl>(X)),
                     const_cast<Decl *>(cast_or_null<Decl>(Y))));
 }
 
-template <class T,
-          std::enable_if_t<std::is_base_of<Decl, T>::value, bool> = true>
+template <class T, std::enable_if_t<std::is_base_of_v<Decl, T>, bool> = true>
 T *getCommonDeclChecked(T *X, T *Y) {
   return cast<T>(getCommonDecl(const_cast<Decl *>(cast<Decl>(X)),
                                const_cast<Decl *>(cast<Decl>(Y))));

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 631dfaebabbd..88262268fc97 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -200,8 +200,8 @@ namespace clang {
     // cast the return value to `T`.
     template <typename T>
     auto import(T *From)
-        -> std::conditional_t<std::is_base_of<Type, T>::value,
-                              Expected<const T *>, Expected<T *>> {
+        -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
+                              Expected<T *>> {
       auto ToOrErr = Importer.Import(From);
       if (!ToOrErr)
         return ToOrErr.takeError();

diff  --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index eaa235bbe610..4cf3bb39c4e8 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -29,7 +29,7 @@ namespace comments {
 #undef ABSTRACT_COMMENT
 
 // DeclInfo is also allocated with a BumpPtrAllocator.
-static_assert(std::is_trivially_destructible<DeclInfo>::value,
+static_assert(std::is_trivially_destructible_v<DeclInfo>,
               "DeclInfo should be trivially destructible!");
 
 const char *Comment::getCommentKindName() const {

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 04808643ab84..1efe9c6d40dc 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -188,8 +188,7 @@ static bool usesTypeVisibility(const NamedDecl *D) {
 /// Does the given declaration have member specialization information,
 /// and if so, is it an explicit specialization?
 template <class T>
-static std::enable_if_t<!std::is_base_of<RedeclarableTemplateDecl, T>::value,
-                        bool>
+static std::enable_if_t<!std::is_base_of_v<RedeclarableTemplateDecl, T>, bool>
 isExplicitMemberSpecialization(const T *D) {
   if (const MemberSpecializationInfo *member =
         D->getMemberSpecializationInfo()) {

diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 82debe4fcae1..d31e879d516f 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -22,7 +22,7 @@ using namespace clang;
 using namespace clang::interp;
 
 template <typename T> inline T ReadArg(Program &P, CodePtr &OpPC) {
-  if constexpr (std::is_pointer<T>::value) {
+  if constexpr (std::is_pointer_v<T>) {
     uint32_t ID = OpPC.read<uint32_t>();
     return reinterpret_cast<T>(P.getNativePointer(ID));
   } else {

diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 20c6c68e44a0..458de974e46b 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -727,9 +727,9 @@ class CFGBuilder {
   // hence strict duck-typing.
   template <typename CallLikeExpr,
             typename = std::enable_if_t<
-                std::is_base_of<CallExpr, CallLikeExpr>::value ||
-                std::is_base_of<CXXConstructExpr, CallLikeExpr>::value ||
-                std::is_base_of<ObjCMessageExpr, CallLikeExpr>::value>>
+                std::is_base_of_v<CallExpr, CallLikeExpr> ||
+                std::is_base_of_v<CXXConstructExpr, CallLikeExpr> ||
+                std::is_base_of_v<ObjCMessageExpr, CallLikeExpr>>>
   void findConstructionContextsForArguments(CallLikeExpr *E) {
     for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
       Expr *Arg = E->getArg(i);

diff  --git a/clang/lib/Analysis/RetainSummaryManager.cpp b/clang/lib/Analysis/RetainSummaryManager.cpp
index 5e9c73534aeb..143c037dda9f 100644
--- a/clang/lib/Analysis/RetainSummaryManager.cpp
+++ b/clang/lib/Analysis/RetainSummaryManager.cpp
@@ -32,7 +32,7 @@ constexpr static bool isOneOf() {
 /// rest of varargs.
 template <class T, class P, class... ToCompare>
 constexpr static bool isOneOf() {
-  return std::is_same<T, P>::value || isOneOf<T, ToCompare...>();
+  return std::is_same_v<T, P> || isOneOf<T, ToCompare...>();
 }
 
 namespace {

diff  --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp
index 6e5e55fb09ce..f9ecd52e5f27 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -42,11 +42,11 @@ void PrettyStackTraceLoc::print(raw_ostream &OS) const {
 // SourceLocation
 //===----------------------------------------------------------------------===//
 
-static_assert(std::is_trivially_destructible<SourceLocation>::value,
+static_assert(std::is_trivially_destructible_v<SourceLocation>,
               "SourceLocation must be trivially destructible because it is "
               "used in unions");
 
-static_assert(std::is_trivially_destructible<SourceRange>::value,
+static_assert(std::is_trivially_destructible_v<SourceRange>,
               "SourceRange must be trivially destructible because it is "
               "used in unions");
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 6b8808078cd6..b004c6c21be4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -199,8 +199,7 @@ static void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
 }
 
 template <typename T> static constexpr bool is_uint64_t_convertible() {
-  return !std::is_same<T, uint64_t>::value &&
-         llvm::is_integral_or_enum<T>::value;
+  return !std::is_same_v<T, uint64_t> && llvm::is_integral_or_enum<T>::value;
 }
 
 template <typename T,

diff  --git a/clang/lib/Lex/MacroArgs.cpp b/clang/lib/Lex/MacroArgs.cpp
index 7ede00b4aa64..1a2fd665fbd0 100644
--- a/clang/lib/Lex/MacroArgs.cpp
+++ b/clang/lib/Lex/MacroArgs.cpp
@@ -62,7 +62,7 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
 
   // Copy the actual unexpanded tokens to immediately after the result ptr.
   if (!UnexpArgTokens.empty()) {
-    static_assert(std::is_trivial<Token>::value,
+    static_assert(std::is_trivial_v<Token>,
                   "assume trivial copyability if copying into the "
                   "uninitialized array (as opposed to reusing a cached "
                   "MacroArgs)");
@@ -94,7 +94,7 @@ MacroArgs *MacroArgs::deallocate() {
   // Run the dtor to deallocate the vectors.
   this->~MacroArgs();
   // Release the memory for the object.
-  static_assert(std::is_trivially_destructible<Token>::value,
+  static_assert(std::is_trivially_destructible_v<Token>,
                 "assume trivially destructible and forego destructors");
   free(this);
 

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index da9aa611793f..a747eb7bfe8c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -202,7 +202,7 @@ static unsigned getNumAttributeArgs(const ParsedAttr &AL) {
 /// A helper function to provide Attribute Location for the Attr types
 /// AND the ParsedAttr.
 template <typename AttrInfo>
-static std::enable_if_t<std::is_base_of<Attr, AttrInfo>::value, SourceLocation>
+static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>, SourceLocation>
 getAttrLoc(const AttrInfo &AL) {
   return AL.getLocation();
 }

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 3db06a51e4eb..6d57cd8542d6 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5491,12 +5491,12 @@ namespace {
 // specialized than primary" check.
 struct GetP2 {
   template <typename T1, typename T2,
-            std::enable_if_t<std::is_same<T1, T2>::value, bool> = true>
+            std::enable_if_t<std::is_same_v<T1, T2>, bool> = true>
   T2 *operator()(T1 *, T2 *P2) {
     return P2;
   }
   template <typename T1, typename T2,
-            std::enable_if_t<!std::is_same<T1, T2>::value, bool> = true>
+            std::enable_if_t<!std::is_same_v<T1, T2>, bool> = true>
   T1 *operator()(T1 *, T2 *) {
     return nullptr;
   }
@@ -5508,7 +5508,7 @@ struct TemplateArgumentListAreEqual {
   TemplateArgumentListAreEqual(ASTContext &Ctx) : Ctx(Ctx) {}
 
   template <typename T1, typename T2,
-            std::enable_if_t<std::is_same<T1, T2>::value, bool> = true>
+            std::enable_if_t<std::is_same_v<T1, T2>, bool> = true>
   bool operator()(T1 *PS1, T2 *PS2) {
     ArrayRef<TemplateArgument> Args1 = PS1->getTemplateArgs().asArray(),
                                Args2 = PS2->getTemplateArgs().asArray();
@@ -5527,7 +5527,7 @@ struct TemplateArgumentListAreEqual {
   }
 
   template <typename T1, typename T2,
-            std::enable_if_t<!std::is_same<T1, T2>::value, bool> = true>
+            std::enable_if_t<!std::is_same_v<T1, T2>, bool> = true>
   bool operator()(T1 *Spec, T2 *Primary) {
     ArrayRef<TemplateArgument> Args1 = Spec->getTemplateArgs().asArray(),
                                Args2 = Primary->getInjectedTemplateArgs();
@@ -5576,7 +5576,7 @@ static TemplateLikeDecl *
 getMoreSpecialized(Sema &S, QualType T1, QualType T2, TemplateLikeDecl *P1,
                    PrimaryDel *P2, TemplateDeductionInfo &Info) {
   constexpr bool IsMoreSpecialThanPrimaryCheck =
-      !std::is_same<TemplateLikeDecl, PrimaryDel>::value;
+      !std::is_same_v<TemplateLikeDecl, PrimaryDel>;
 
   bool Better1 = isAtLeastAsSpecializedAs(S, T1, T2, P2, Info);
   if (IsMoreSpecialThanPrimaryCheck && !Better1)

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 1a2578b85f08..a90e17fc496d 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -912,9 +912,9 @@ static void printStateTraitWithLocationContextJson(
 
   // Try to do as much compile time checking as possible.
   // FIXME: check for invocable instead of function?
-  static_assert(std::is_function<std::remove_pointer_t<Printer>>::value,
+  static_assert(std::is_function_v<std::remove_pointer_t<Printer>>,
                 "Printer is not a function!");
-  static_assert(std::is_convertible<Printer, RequiredType>::value,
+  static_assert(std::is_convertible_v<Printer, RequiredType>,
                 "Printer doesn't have the required type!");
 
   if (LCtx && !State->get<Trait>().isEmpty()) {

diff  --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
index 0821863adcc6..6b359c1910bc 100644
--- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -117,13 +117,11 @@ class SyntaxTree::Impl {
   Impl(SyntaxTree *Parent, Stmt *N, ASTContext &AST);
   template <class T>
   Impl(SyntaxTree *Parent,
-       std::enable_if_t<std::is_base_of<Stmt, T>::value, T> *Node,
-       ASTContext &AST)
+       std::enable_if_t<std::is_base_of_v<Stmt, T>, T> *Node, ASTContext &AST)
       : Impl(Parent, dyn_cast<Stmt>(Node), AST) {}
   template <class T>
   Impl(SyntaxTree *Parent,
-       std::enable_if_t<std::is_base_of<Decl, T>::value, T> *Node,
-       ASTContext &AST)
+       std::enable_if_t<std::is_base_of_v<Decl, T>, T> *Node, ASTContext &AST)
       : Impl(Parent, dyn_cast<Decl>(Node), AST) {}
 
   SyntaxTree *Parent;

diff  --git a/clang/unittests/Lex/HeaderMapTest.cpp b/clang/unittests/Lex/HeaderMapTest.cpp
index 4220edb2908e..5484041844ea 100644
--- a/clang/unittests/Lex/HeaderMapTest.cpp
+++ b/clang/unittests/Lex/HeaderMapTest.cpp
@@ -115,8 +115,7 @@ template <class FileTy, class PaddingTy> struct PaddedFile {
 TEST(HeaderMapTest, lookupFilenameTruncatedSuffix) {
   typedef HMapFileMock<2, 64 - sizeof(HMapHeader) - 2 * sizeof(HMapBucket)>
       FileTy;
-  static_assert(std::is_standard_layout<FileTy>::value,
-                "Expected standard layout");
+  static_assert(std::is_standard_layout_v<FileTy>, "Expected standard layout");
   static_assert(sizeof(FileTy) == 64, "check the math");
   PaddedFile<FileTy, uint64_t> P;
   auto &File = P.File;
@@ -151,8 +150,7 @@ TEST(HeaderMapTest, lookupFilenameTruncatedSuffix) {
 TEST(HeaderMapTest, lookupFilenameTruncatedPrefix) {
   typedef HMapFileMock<2, 64 - sizeof(HMapHeader) - 2 * sizeof(HMapBucket)>
       FileTy;
-  static_assert(std::is_standard_layout<FileTy>::value,
-                "Expected standard layout");
+  static_assert(std::is_standard_layout_v<FileTy>, "Expected standard layout");
   static_assert(sizeof(FileTy) == 64, "check the math");
   PaddedFile<FileTy, uint64_t> P;
   auto &File = P.File;

diff  --git a/clang/unittests/Tooling/ASTSelectionTest.cpp b/clang/unittests/Tooling/ASTSelectionTest.cpp
index 88988ef44787..531f9ac89f44 100644
--- a/clang/unittests/Tooling/ASTSelectionTest.cpp
+++ b/clang/unittests/Tooling/ASTSelectionTest.cpp
@@ -101,22 +101,22 @@ void checkDeclName(const SelectedASTNode &Node, StringRef Name) {
 }
 
 template <typename T>
-const SelectedASTNode &checkNode(
-    const SelectedASTNode &StmtNode, SourceSelectionKind SelectionKind,
-    unsigned NumChildren = 0,
-    std::enable_if_t<std::is_base_of<Stmt, T>::value, T> *StmtOverloadChecker =
-        nullptr) {
+const SelectedASTNode &
+checkNode(const SelectedASTNode &StmtNode, SourceSelectionKind SelectionKind,
+          unsigned NumChildren = 0,
+          std::enable_if_t<std::is_base_of_v<Stmt, T>, T> *StmtOverloadChecker =
+              nullptr) {
   checkNodeImpl(isa<T>(StmtNode.Node.get<Stmt>()), StmtNode, SelectionKind,
                 NumChildren);
   return StmtNode;
 }
 
 template <typename T>
-const SelectedASTNode &checkNode(
-    const SelectedASTNode &DeclNode, SourceSelectionKind SelectionKind,
-    unsigned NumChildren = 0, StringRef Name = "",
-    std::enable_if_t<std::is_base_of<Decl, T>::value, T> *DeclOverloadChecker =
-        nullptr) {
+const SelectedASTNode &
+checkNode(const SelectedASTNode &DeclNode, SourceSelectionKind SelectionKind,
+          unsigned NumChildren = 0, StringRef Name = "",
+          std::enable_if_t<std::is_base_of_v<Decl, T>, T> *DeclOverloadChecker =
+              nullptr) {
   checkNodeImpl(isa<T>(DeclNode.Node.get<Decl>()), DeclNode, SelectionKind,
                 NumChildren);
   if (!Name.empty())

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 712d2bd40fbb..44cf42fa944a 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -151,9 +151,8 @@ TEST_F(TreeTest, Iterators) {
   // FIXME: mutate and observe no invalidation. Mutations are private for now...
   auto It = Range.begin();
   auto CIt = ConstRange.begin();
-  static_assert(std::is_same<decltype(*It), syntax::Node &>::value,
-                "mutable range");
-  static_assert(std::is_same<decltype(*CIt), const syntax::Node &>::value,
+  static_assert(std::is_same_v<decltype(*It), syntax::Node &>, "mutable range");
+  static_assert(std::is_same_v<decltype(*CIt), const syntax::Node &>,
                 "const range");
 
   for (unsigned I = 0; I < 3; ++I) {


        


More information about the cfe-commits mailing list