[PATCH] D104703: [ADT] Extend EnableIfCallable for callables with incomplete returns
Fehr Mathieu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 22 05:15:41 PDT 2021
math-fehr created this revision.
Herald added a subscriber: dexonsmith.
math-fehr requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
std::is_convertible has no defined behavior when its arguments
are incomplete, even if they are equal. In practice, it returns false.
Adding std::is_same allows us to use the constructor using a callable,
even if the return value is incomplete. We also check the case where
we convert a T into a const T.
Repository:
rG LLVM Github Monorepo
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,15 @@
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<
+ std::is_void<Ret>::value ||
+ std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
+ Ret>::value ||
+ std::is_same<const decltype(std::declval<CallableT>()(std::declval<Params>()...)),
+ Ret>::value ||
+ 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.353613.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/98ea3463/attachment.bin>
More information about the llvm-commits
mailing list