Skip to content

Commit

Permalink
Fix warnings caused by macromodel (#1074)
Browse files Browse the repository at this point in the history
* add null_terminated_c_str_v for a null terminated string literal

* fix __builtin_addressof(::fast_io::char_literal_v<ch_type, 0>

* string_view uses null_terminated_c_str_v

* Fix warnings caused by macromodel

Why do you not compile code with warnings enabled? this is so painful

---------

Co-authored-by: hearyldp <[email protected]>
  • Loading branch information
trcrsired and hearyldp authored Feb 10, 2025
1 parent ce3b8de commit 0a23637
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
32 changes: 32 additions & 0 deletions include/fast_io_core_impl/literals/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,38 @@ inline constexpr ch_type char_literal(char8_t ch) noexcept
template <char8_t ch, ::std::integral ch_type>
inline constexpr ch_type char_literal_v{char_literal<ch_type>(ch)};

template <::std::integral ch_type>
inline constexpr ch_type const *null_terminated_c_str() noexcept
{
if constexpr (::std::same_as<ch_type, char>)
{
return "";
}
else if constexpr (::std::same_as<ch_type, wchar_t>)
{
return L"";
}
else if constexpr (::std::same_as<ch_type, char8_t>)
{
return u8"";
}
else if constexpr (::std::same_as<ch_type, char16_t>)
{
return u"";
}
else if constexpr (::std::same_as<ch_type, char32_t>)
{
return U"";
}
else
{
return __builtin_addressof(::fast_io::char_literal_v<0, ch_type>);
}
}

template <::std::integral ch_type>
inline constexpr ch_type const *null_terminated_c_str_v{::fast_io::null_terminated_c_str<ch_type>()};

template <::std::integral ch_type>
#if __has_cpp_attribute(__gnu__::__always_inline__)
[[__gnu__::__always_inline__]]
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_dsal/impl/cstring_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class basic_cstring_view : private ::fast_io::containers::basic_string_view<char
using string_view_type::n;

inline constexpr basic_cstring_view() noexcept
: string_view_type(__builtin_addressof(::fast_io::char_literal_v<0, char_type>), 0)
: string_view_type(::fast_io::null_terminated_c_str_v<char_type>, 0)
{}
inline constexpr void clear() noexcept
{
this->ptr = __builtin_addressof(::fast_io::char_literal_v<0, char_type>);
this->ptr = ::fast_io::null_terminated_c_str_v<char_type>;
this->n = 0;
}
inline constexpr basic_cstring_view(::std::nullptr_t) = delete;
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_hosted/filesystem/win32_9xa_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ inline auto win32_9xa_22_api_dispatcher(::fast_io::win32_9xa_dir_handle const &o
}
}

template <::fast_io::details::posix_api_12 dsp, typename... Args>
template <::fast_io::details::posix_api_12 dsp>
inline auto win32_9xa_12_api_dispatcher(char8_t const *oldpath_c_str, ::std::size_t oldpath_size,
::fast_io::win32_9xa_dir_handle const &newdirhd, char8_t const *newpath_c_str, ::std::size_t newpath_size, Args... args)
::fast_io::win32_9xa_dir_handle const &newdirhd, char8_t const *newpath_c_str, ::std::size_t newpath_size)
{
if constexpr (dsp == ::fast_io::details::posix_api_12::symlinkat)
{
Expand Down
8 changes: 5 additions & 3 deletions include/fast_io_hosted/process/ipc/win32/named_pipe_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ inline void *win32_family_create_named_pipe_ipc_server_impl(win32_named_pipe_cha
{
// check filename
using family_internal_char_type = win32_named_pipe_internal_char_type<family>;
#if 0
using family_internal_str = win32_named_pipe_internal_str<family>;

#endif
using family_internal_char_type_const_may_alias_ptr
#if __has_cpp_attribute(__gnu__::__may_alias__)
[[__gnu__::__may_alias__]]
Expand Down Expand Up @@ -252,8 +253,9 @@ inline void *win32_family_ipc_named_pipe_client_connect_impl(win32_named_pipe_ch
// check filename
using family_char_type = win32_named_pipe_char_type<family>;
using family_internal_char_type = win32_named_pipe_internal_char_type<family>;
#if 0
using family_internal_str = win32_named_pipe_internal_str<family>;

#endif
using family_internal_char_type_const_may_alias_ptr
#if __has_cpp_attribute(__gnu__::__may_alias__)
[[__gnu__::__may_alias__]]
Expand Down Expand Up @@ -347,7 +349,7 @@ inline void *win32_family_ipc_named_pipe_client_connect_impl(win32_named_pipe_ch
::fast_io::open_mode om{};
if ((mode & ::fast_io::ipc_mode::in) == ::fast_io::ipc_mode::in)
{
om |= ::fast_io::open_mode::in;
om |= ::fast_io::open_mode::in;
}
if ((mode & ::fast_io::ipc_mode::out) == ::fast_io::ipc_mode::out)
{
Expand Down

0 comments on commit 0a23637

Please sign in to comment.