[PATCH] D81554: [ADT] Allow IsSizeLessThanThresholdT for incomplete types. NFC

Yevgeny Rouban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 05:25:42 PDT 2020


yrouban created this revision.
yrouban added reviewers: chandlerc, fedor.sergeev, vvereschaka.
Herald added a subscriber: dexonsmith.
Herald added a project: LLVM.
yrouban added a reviewer: DaniilSuchkov.

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;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81554

Files:
  llvm/include/llvm/ADT/FunctionExtras.h


Index: llvm/include/llvm/ADT/FunctionExtras.h
===================================================================
--- llvm/include/llvm/ADT/FunctionExtras.h
+++ llvm/include/llvm/ADT/FunctionExtras.h
@@ -46,12 +46,12 @@
 class unique_function<ReturnT(ParamTs...)> {
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81554.269799.patch
Type: text/x-patch
Size: 1085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200610/0c285d6f/attachment.bin>


More information about the llvm-commits mailing list