[llvm] e857896 - [ADT] Replace STLForwardCompat.h's C++17 equivalents

Joe Loser via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 05:57:46 PDT 2022


Author: Joe Loser
Date: 2022-08-12T06:55:59-06:00
New Revision: e8578968f684997840f680ed62bff5cad0accc13

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

LOG: [ADT] Replace STLForwardCompat.h's C++17 equivalents

STLForwardCompat.h defines several utilities and type traits to mimic that of
the ones in the C++17 standard library. Now that LLVM is built with the C++17
standards mode, remove use of these equivalents in favor of the ones from the
standard library.

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

Added: 
    

Modified: 
    clang/include/clang/Basic/DirectoryEntry.h
    clang/include/clang/Basic/FileEntry.h
    llvm/include/llvm/ADT/Any.h
    llvm/include/llvm/ADT/FunctionExtras.h
    llvm/include/llvm/ADT/Optional.h
    llvm/include/llvm/ADT/STLExtras.h
    llvm/include/llvm/Support/HashBuilder.h
    llvm/unittests/ADT/OptionalTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h
index f1ec63d975a37..19d52c09dbcce 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -22,6 +22,8 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorOr.h"
 
+#include <utility>
+
 namespace clang {
 namespace FileMgr {
 
@@ -125,7 +127,7 @@ template <class RefTy> class MapEntryOptionalStorage {
   MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {}
 
   template <class... ArgTypes>
-  explicit MapEntryOptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
+  explicit MapEntryOptionalStorage(std::in_place_t, ArgTypes &&...Args)
       : MaybeRef(std::forward<ArgTypes>(Args)...) {}
 
   void reset() { MaybeRef = optional_none_tag(); }
@@ -189,8 +191,8 @@ class OptionalStorage<clang::DirectoryEntryRef>
   OptionalStorage() = default;
 
   template <class... ArgTypes>
-  explicit OptionalStorage(in_place_t, ArgTypes &&...Args)
-      : StorageImpl(in_place_t{}, std::forward<ArgTypes>(Args)...) {}
+  explicit OptionalStorage(std::in_place_t, ArgTypes &&...Args)
+      : StorageImpl(std::in_place_t{}, std::forward<ArgTypes>(Args)...) {}
 
   OptionalStorage &operator=(clang::DirectoryEntryRef Ref) {
     StorageImpl::operator=(Ref);

diff  --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index 3ca07cb422b64..d9b92a73a1d82 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -24,6 +24,8 @@
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
 
+#include <utility>
+
 namespace llvm {
 
 class MemoryBuffer;
@@ -222,8 +224,8 @@ class OptionalStorage<clang::FileEntryRef>
   OptionalStorage() = default;
 
   template <class... ArgTypes>
-  explicit OptionalStorage(in_place_t, ArgTypes &&...Args)
-      : StorageImpl(in_place_t{}, std::forward<ArgTypes>(Args)...) {}
+  explicit OptionalStorage(std::in_place_t, ArgTypes &&...Args)
+      : StorageImpl(std::in_place_t{}, std::forward<ArgTypes>(Args)...) {}
 
   OptionalStorage &operator=(clang::FileEntryRef Ref) {
     StorageImpl::operator=(Ref);

diff  --git a/llvm/include/llvm/ADT/Any.h b/llvm/include/llvm/ADT/Any.h
index 1c7ba03717816..649a9986c0a41 100644
--- a/llvm/include/llvm/ADT/Any.h
+++ b/llvm/include/llvm/ADT/Any.h
@@ -68,8 +68,8 @@ class LLVM_EXTERNAL_VISIBILITY Any {
   // instead.
   template <typename T,
             std::enable_if_t<
-                llvm::conjunction<
-                    llvm::negation<std::is_same<std::decay_t<T>, Any>>,
+                std::conjunction<
+                    std::negation<std::is_same<std::decay_t<T>, Any>>,
                     // We also disable this overload when an `Any` object can be
                     // converted to the parameter type because in that case,
                     // this constructor may combine with that conversion during
@@ -80,7 +80,7 @@ class LLVM_EXTERNAL_VISIBILITY Any {
                     // DR in `std::any` as well, but we're going ahead and
                     // adopting it to work-around usage of `Any` with types that
                     // need to be implicitly convertible from an `Any`.
-                    llvm::negation<std::is_convertible<Any, std::decay_t<T>>>,
+                    std::negation<std::is_convertible<Any, std::decay_t<T>>>,
                     std::is_copy_constructible<std::decay_t<T>>>::value,
                 int> = 0>
   Any(T &&Value) {

diff  --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 5a37417ddde5d..8ff0fb787a77d 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -65,7 +65,7 @@ template <typename CallableT, typename ThisT>
 using EnableUnlessSameType =
     std::enable_if_t<!std::is_same<remove_cvref_t<CallableT>, ThisT>::value>;
 template <typename CallableT, typename Ret, typename... Params>
-using EnableIfCallable = std::enable_if_t<llvm::disjunction<
+using EnableIfCallable = std::enable_if_t<std::disjunction<
     std::is_void<Ret>,
     std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
                  Ret>,

diff  --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 09770c4f94a0e..1862a2d703aad 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -81,7 +81,7 @@ class OptionalStorage {
   }
 
   template <class... Args>
-  constexpr explicit OptionalStorage(in_place_t, Args &&...args)
+  constexpr explicit OptionalStorage(std::in_place_t, Args &&...args)
       : val(std::forward<Args>(args)...), hasVal(true) {}
 
   void reset() noexcept {
@@ -196,7 +196,7 @@ template <typename T> class OptionalStorage<T, true> {
   OptionalStorage &operator=(OptionalStorage &&other) = default;
 
   template <class... Args>
-  constexpr explicit OptionalStorage(in_place_t, Args &&...args)
+  constexpr explicit OptionalStorage(std::in_place_t, Args &&...args)
       : val(std::forward<Args>(args)...), hasVal(true) {}
 
   void reset() noexcept {
@@ -275,15 +275,15 @@ template <typename T> class Optional {
   constexpr Optional() = default;
   constexpr Optional(NoneType) {}
 
-  constexpr Optional(const T &y) : Storage(in_place, y) {}
+  constexpr Optional(const T &y) : Storage(std::in_place, y) {}
   constexpr Optional(const Optional &O) = default;
 
-  constexpr Optional(T &&y) : Storage(in_place, std::move(y)) {}
+  constexpr Optional(T &&y) : Storage(std::in_place, std::move(y)) {}
   constexpr Optional(Optional &&O) = default;
 
   template <typename... ArgTypes>
-  constexpr Optional(in_place_t, ArgTypes &&...Args)
-      : Storage(in_place, std::forward<ArgTypes>(Args)...) {}
+  constexpr Optional(std::in_place_t, ArgTypes &&...Args)
+      : Storage(std::in_place, std::forward<ArgTypes>(Args)...) {}
 
   Optional &operator=(T &&y) {
     Storage = std::move(y);

diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index dd8b2095ba7ee..45641ec144248 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -155,12 +155,12 @@ struct function_traits<ReturnType (&)(Args...), false>
 /// traits class for checking whether type T is one of any of the given
 /// types in the variadic list.
 template <typename T, typename... Ts>
-using is_one_of = disjunction<std::is_same<T, Ts>...>;
+using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
 
 /// traits class for checking whether type T is a base class for all
 ///  the given types in the variadic list.
 template <typename T, typename... Ts>
-using are_base_of = conjunction<std::is_base_of<T, Ts>...>;
+using are_base_of = std::conjunction<std::is_base_of<T, Ts>...>;
 
 namespace detail {
 template <typename T, typename... Us> struct TypesAreDistinct;
@@ -1386,12 +1386,12 @@ template <> struct rank<0> {};
 /// traits class for checking whether type T is one of any of the given
 /// types in the variadic list.
 template <typename T, typename... Ts>
-using is_one_of = disjunction<std::is_same<T, Ts>...>;
+using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
 
 /// traits class for checking whether type T is a base class for all
 ///  the given types in the variadic list.
 template <typename T, typename... Ts>
-using are_base_of = conjunction<std::is_base_of<T, Ts>...>;
+using are_base_of = std::conjunction<std::is_base_of<T, Ts>...>;
 
 namespace detail {
 template <typename... Ts> struct Visitor;
@@ -1550,7 +1550,7 @@ namespace detail {
 template <typename T>
 // We can use qsort if the iterator type is a pointer and the underlying value
 // is trivially copyable.
-using sort_trivially_copyable = conjunction<
+using sort_trivially_copyable = std::conjunction<
     std::is_pointer<T>,
     std::is_trivially_copyable<typename std::iterator_traits<T>::value_type>>;
 } // namespace detail

diff  --git a/llvm/include/llvm/Support/HashBuilder.h b/llvm/include/llvm/Support/HashBuilder.h
index 9d7680d2b6677..51ca97e1597de 100644
--- a/llvm/include/llvm/Support/HashBuilder.h
+++ b/llvm/include/llvm/Support/HashBuilder.h
@@ -76,7 +76,7 @@ template <typename HasherT> class HashBuilderBase {
 
   template <typename... ArgTypes>
   explicit HashBuilderBase(ArgTypes &&...Args)
-      : OptionalHasher(in_place, std::forward<ArgTypes>(Args)...),
+      : OptionalHasher(std::in_place, std::forward<ArgTypes>(Args)...),
         Hasher(*OptionalHasher) {}
 
 private:

diff  --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp
index 8d01b0df3fc34..3db84ed4c3306 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -14,7 +14,7 @@
 #include "gtest/gtest.h"
 
 #include <array>
-
+#include <utility>
 
 using namespace llvm;
 
@@ -201,7 +201,7 @@ TEST(OptionalTest, NullCopyConstructionTest) {
 
 TEST(OptionalTest, InPlaceConstructionNonDefaultConstructibleTest) {
   NonDefaultConstructible::ResetCounts();
-  { Optional<NonDefaultConstructible> A{in_place, 1}; }
+  { Optional<NonDefaultConstructible> A{std::in_place, 1}; }
   EXPECT_EQ(0u, NonDefaultConstructible::CopyConstructions);
   EXPECT_EQ(0u, NonDefaultConstructible::CopyAssignments);
   EXPECT_EQ(1u, NonDefaultConstructible::Destructions);
@@ -247,7 +247,7 @@ static_assert(!std::is_trivially_copyable<Optional<MultiArgConstructor>>::value,
 TEST(OptionalTest, Emplace) {
   MultiArgConstructor::ResetCounts();
   Optional<MultiArgConstructor> A;
-  
+
   A.emplace(1, 2);
   EXPECT_TRUE(A.has_value());
   EXPECT_TRUE(A.has_value());
@@ -266,12 +266,12 @@ TEST(OptionalTest, Emplace) {
 TEST(OptionalTest, InPlaceConstructionMultiArgConstructorTest) {
   MultiArgConstructor::ResetCounts();
   {
-    Optional<MultiArgConstructor> A{in_place, 1, 2};
+    Optional<MultiArgConstructor> A{std::in_place, 1, 2};
     EXPECT_TRUE(A.has_value());
     EXPECT_TRUE(A.has_value());
     EXPECT_EQ(1, A->x);
     EXPECT_EQ(2, A->y);
-    Optional<MultiArgConstructor> B{in_place, 5, false};
+    Optional<MultiArgConstructor> B{std::in_place, 5, false};
     EXPECT_TRUE(B.has_value());
     EXPECT_TRUE(B.has_value());
     EXPECT_EQ(5, B->x);
@@ -284,7 +284,7 @@ TEST(OptionalTest, InPlaceConstructionMultiArgConstructorTest) {
 TEST(OptionalTest, InPlaceConstructionAndEmplaceEquivalentTest) {
   MultiArgConstructor::ResetCounts();
   {
-    Optional<MultiArgConstructor> A{in_place, 1, 2};
+    Optional<MultiArgConstructor> A{std::in_place, 1, 2};
     Optional<MultiArgConstructor> B;
     B.emplace(1, 2);
     EXPECT_EQ(0u, MultiArgConstructor::Destructions);
@@ -442,7 +442,7 @@ TEST(OptionalTest, ImmovableEmplace) {
 
 TEST(OptionalTest, ImmovableInPlaceConstruction) {
   Immovable::ResetCounts();
-  Optional<Immovable> A{in_place, 4};
+  Optional<Immovable> A{std::in_place, 4};
   EXPECT_TRUE((bool)A);
   EXPECT_EQ(4, A->val);
   EXPECT_EQ(1u, Immovable::Constructions);


        


More information about the llvm-commits mailing list