Skip to content

Commit d894a91

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 d894a91

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

include/cpp2util.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,17 @@ template<typename T>
491491
//
492492
//-----------------------------------------------------------------------
493493
//
494+
template<typename, typename = void>
495+
constexpr bool is_complete_type_v = false;
496+
497+
template<typename T>
498+
constexpr bool is_complete_type_v<T, std::void_t<decltype(sizeof(T))>> = true;
499+
494500
template<typename T>
495501
constexpr bool prefer_pass_by_value =
496-
sizeof(T) < 2*sizeof(void*) && std::is_trivially_copy_constructible_v<T>;
502+
is_complete_type_v<T>
503+
&& sizeof(T) < 2*sizeof(void*)
504+
&& std::is_trivially_copy_constructible_v<T>;
497505

498506
template<typename T>
499507
using in =

0 commit comments

Comments
 (0)