[llvm] 7d9a162 - [ADT] Allow IsSizeLessThanThresholdT for incomplete types. NFC
Yevgeny Rouban via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 21:03:21 PDT 2020
Author: Yevgeny Rouban
Date: 2020-08-21T11:01:57+07:00
New Revision: 7d9a16241fdd800a394e5cb4ecdf76f6bb8c9d9f
URL: https://github.com/llvm/llvm-project/commit/7d9a16241fdd800a394e5cb4ecdf76f6bb8c9d9f
DIFF: https://github.com/llvm/llvm-project/commit/7d9a16241fdd800a394e5cb4ecdf76f6bb8c9d9f.diff
LOG: [ADT] Allow IsSizeLessThanThresholdT for incomplete types. NFC
If the type T is incomplete then sizeof(T) results in C++ compilation error at line:
static constexpr bool value = sizeof(T) <= (2 * sizeof(void *));
This patch allows incomplete types in parameters of function. Example:
using SomeFunc = void(SomeIncompleteType &);
llvm::unique_function<SomeFuncType> SomeFunc;
Reviewers: DaniilSuchkov, vvereschaka
Differential Revision: https://reviews.llvm.org/D81554
Added:
Modified:
llvm/include/llvm/ADT/FunctionExtras.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 4c75e4d2547b..7f8fb103f148 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -64,12 +64,12 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
protected:
static constexpr size_t InlineStorageSize = sizeof(void *) * 3;
- // MSVC has a bug and ICEs if we give it a particular dependent value
- // expression as part of the `std::conditional` below. To work around this,
- // we build that into a template struct's constexpr bool.
- template <typename T> struct IsSizeLessThanThresholdT {
- static constexpr bool value = sizeof(T) <= (2 * sizeof(void *));
- };
+ template <typename T, class = void>
+ struct IsSizeLessThanThresholdT : std::false_type {};
+
+ template <typename T>
+ struct IsSizeLessThanThresholdT<
+ T, std::enable_if_t<sizeof(T) <= 2 * sizeof(void *)>> : std::true_type {};
// Provide a type function to map parameters that won't observe extra copies
// or moves and which are small enough to likely pass in register to values
More information about the llvm-commits
mailing list