[PATCH] D104703: [ADT] Extend EnableIfCallable for callables with incomplete returns
Fehr Mathieu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 13 15:32:59 PDT 2021
math-fehr updated this revision to Diff 358448.
math-fehr added a comment.
Remove llvm::conjunctions, and use llvm::disjunction
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/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/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::disjunction<
+ 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.358448.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210713/f8c7d9c7/attachment.bin>
More information about the llvm-commits
mailing list