diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt index 30bbf3ae96d26..51230c638cdcf 100644 --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -72,6 +72,7 @@ add_header_library( .str_to_num_result libc.src.errno.errno libc.src.__support.CPP.limits + libc.src.__support.CPP.type_traits libc.src.__support.common ) diff --git a/libc/src/__support/str_to_integer.h b/libc/src/__support/str_to_integer.h index 965ac11cb2173..b7af39d09bb47 100644 --- a/libc/src/__support/str_to_integer.h +++ b/libc/src/__support/str_to_integer.h @@ -10,6 +10,7 @@ #define LIBC_SRC_SUPPORT_STR_TO_INTEGER_H #include "src/__support/CPP/limits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/common.h" #include "src/__support/ctype_utils.h" #include "src/__support/str_to_num_result.h" @@ -142,7 +143,9 @@ LIBC_INLINE StrToNumResult strtointeger(const char *__restrict src, return {cpp::numeric_limits::min(), str_len, error_val}; } - return {is_positive ? static_cast(result) : -static_cast(result), + return {is_positive + ? static_cast(result) + : static_cast(-static_cast>(result)), str_len, error_val}; }