[PATCH] D104703: [ADT] Extend EnableIfCallable for callables with incomplete returns
Fehr Mathieu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 06:23:11 PDT 2021
math-fehr updated this revision to Diff 357923.
math-fehr added a comment.
Fix compilation on windows by introducing and using llvm::conjuctions
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104703/new/
https://reviews.llvm.org/D104703
Files:
llvm/include/llvm/ADT/FunctionExtras.h
llvm/include/llvm/Support/type_traits.h
llvm/unittests/ADT/FunctionExtrasTest.cpp
Index: llvm/unittests/ADT/FunctionExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/FunctionExtrasTest.cpp
+++ llvm/unittests/ADT/FunctionExtrasTest.cpp
@@ -291,4 +291,23 @@
unique_function<Templated<Incomplete> *()> IncompleteResultPointer;
}
+// Incomplete function returning an incomplete type
+Incomplete incompleteFunction();
+const Incomplete incompleteFunctionConst();
+
+// Check that we can assign a callable to a unique_function when the
+// callable return value is incomplete.
+TEST(UniqueFunctionTest, IncompleteCallableType) {
+ unique_function<Incomplete()> IncompleteReturnInCallable{incompleteFunction};
+ unique_function<const Incomplete()> IncompleteReturnInCallableConst{
+ incompleteFunctionConst};
+ unique_function<const Incomplete()> IncompleteReturnInCallableConstConversion{
+ incompleteFunction};
+}
+
+// Define the incomplete function
+class Incomplete {};
+Incomplete incompleteFunction() { return {}; }
+const Incomplete incompleteFunctionConst() { return {}; }
+
} // anonymous namespace
Index: llvm/include/llvm/Support/type_traits.h
===================================================================
--- llvm/include/llvm/Support/type_traits.h
+++ llvm/include/llvm/Support/type_traits.h
@@ -185,6 +185,13 @@
class is_trivially_copyable<T*> : public std::true_type {
};
+/// An implementation of `std::conjunctions` since we have users with STLs that
+/// don't yet include it.
+template <typename... Conds> struct conjunctions : std::true_type {};
+template <typename Cond1> struct conjunctions<Cond1> : Cond1 {};
+template <class C1, class... Cs>
+struct conjunctions<C1, Cs...>
+ : std::conditional<bool(C1::value), C1, conjunctions<Cs...>>::type {};
} // end namespace llvm
Index: llvm/include/llvm/ADT/FunctionExtras.h
===================================================================
--- llvm/include/llvm/ADT/FunctionExtras.h
+++ llvm/include/llvm/ADT/FunctionExtras.h
@@ -64,11 +64,16 @@
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<std::is_void<Ret>::value ||
- std::is_convertible<decltype(std::declval<CallableT>()(
- std::declval<Params>()...)),
- Ret>::value>;
+using EnableIfCallable = std::enable_if_t<llvm::conjunctions<
+ std::is_void<Ret>,
+ std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
+ Ret>,
+ std::is_same<const decltype(std::declval<CallableT>()(
+ std::declval<Params>()...)),
+ Ret>,
+ std::is_convertible<decltype(std::declval<CallableT>()(
+ std::declval<Params>()...)),
+ Ret>>::value>;
template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
protected:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104703.357923.patch
Type: text/x-patch
Size: 3058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210712/a4fab6b2/attachment.bin>
More information about the llvm-commits
mailing list