Skip to content

Commit 6cd3450

Browse files
committed
Add check it type is complete to prefer_pass_by_value
In current implementation of `prefer_pass_by_value` we check sizeof type. It fails in case that type is incomplete. This change adds a check if there is a possibility to check the sizeof type.
1 parent 4c52d2d commit 6cd3450

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/cpp2util.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,13 @@ template<typename T>
491491
//
492492
//-----------------------------------------------------------------------
493493
//
494+
template<typename T, typename = void>
495+
constexpr bool prefer_pass_by_value = false;
496+
494497
template<typename T>
495-
constexpr bool prefer_pass_by_value =
496-
sizeof(T) < 2*sizeof(void*) && std::is_trivially_copy_constructible_v<T>;
498+
constexpr bool prefer_pass_by_value<T, std::void_t<decltype(sizeof(T))>> =
499+
sizeof(T) < 2*sizeof(void*)
500+
&& std::is_trivially_copy_constructible_v<T>;
497501

498502
template<typename T>
499503
using in =

0 commit comments

Comments
 (0)