diff --git a/CMakeLists.txt b/CMakeLists.txt index d874adb..8a224e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,8 @@ option(BUILD_TESTS "Enable testing" OFF) option(BUILD_HEADER_ONLY "Enable header only build" OFF) mark_as_advanced(ENABLE_PROFILING) +set(CMAKE_CXX_STANDARD 20) + set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/algorithm.tpp" "include/rexy/utility.hpp" "include/rexy/hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp" "include/rexy/format.hpp" "include/rexy/format.tpp") if(BUILD_HEADER_ONLY) @@ -45,6 +47,12 @@ else() set(LIBREXY_LIBFLAGS "-lrexy -lpthread") target_link_libraries(rexy "-lpthread") endif() + + if(MSVC) + target_compile_options(rexy PRIVATE "/Zc:__cplusplus" "/Wall") + else() + target_compile_options(rexy PRIVATE "-Wall" "-Wextra" "-pedantic") + endif() set_target_properties(rexy PROPERTIES VERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}.${librexy_VERSION_REVISION}") if(ENABLE_SSO) @@ -57,12 +65,15 @@ else() target_link_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls) endif() - target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++20) endif() if(BUILD_TESTS) add_library(ensure OBJECT "src/ensure.cpp") - target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++20) + if(MSVC) + target_compile_options(ensure PRIVATE "/Zc:__cplusplus" "/Wall") + else() + target_compile_options(ensure PRIVATE "-Wall" "-Wextra" "-pedantic") + endif() enable_testing() add_subdirectory(tests) endif() diff --git a/include/rexy/compat/string_base.hpp b/include/rexy/compat/string_base.hpp index 7a245d3..9b24501 100644 --- a/include/rexy/compat/string_base.hpp +++ b/include/rexy/compat/string_base.hpp @@ -22,7 +22,7 @@ #include //size_t namespace rexy{ - static constexpr std::size_t npos = std::size_t{-1}; + static constexpr std::size_t npos = std::size_t(-1); } #ifdef __cpp_concepts diff --git a/include/rexy/detail/format/basic_types.hpp b/include/rexy/detail/format/basic_types.hpp index b6fe713..4db36b6 100644 --- a/include/rexy/detail/format/basic_types.hpp +++ b/include/rexy/detail/format/basic_types.hpp @@ -25,7 +25,7 @@ namespace rexy::fmt::detail{ - static constexpr std::size_t invalid_arg_index = std::size_t{-1}; + static constexpr std::size_t invalid_arg_index = std::size_t(-1); template diff --git a/include/rexy/detail/format/formatter.tpp b/include/rexy/detail/format/formatter.tpp index 4259fe4..15ea065 100644 --- a/include/rexy/detail/format/formatter.tpp +++ b/include/rexy/detail/format/formatter.tpp @@ -328,9 +328,9 @@ namespace rexy::fmt::detail{ template constexpr OutIt perform_localized_integer_write(OutIt out, const char* start, const char* last, const std::locale& loc){ const auto& facet = std::use_facet>(loc); - const int group_size = facet.grouping()[0]; + const int group_size = int(facet.grouping()[0]); const Char sep = facet.thousands_sep(); - const int len = last - start; + const int len = int(last - start); if(group_size != 0){ int write_count = (len-1) % group_size; *out++ = *start++; @@ -342,7 +342,7 @@ namespace rexy::fmt::detail{ break; } *out++ = sep; - write_count = std::min(group_size, int{last - start}); + write_count = std::min(group_size, int(last - start)); } return std::move(out); } diff --git a/include/rexy/detail/format/named_args.tpp b/include/rexy/detail/format/named_args.tpp index 356be7d..8cc38a6 100644 --- a/include/rexy/detail/format/named_args.tpp +++ b/include/rexy/detail/format/named_args.tpp @@ -45,7 +45,7 @@ namespace rexy::fmt::detail{ } template constexpr std::size_t find_static_named_arg_id(It first, It last){ - if constexpr(!sizeof...(Args)){ + if constexpr(sizeof...(Args) == 0){ return invalid_arg_index; }else{ return find_static_named_arg_id_impl(first, last); diff --git a/include/rexy/detail/format/specs_handler.tpp b/include/rexy/detail/format/specs_handler.tpp index 68e4bc6..0d27e4c 100644 --- a/include/rexy/detail/format/specs_handler.tpp +++ b/include/rexy/detail/format/specs_handler.tpp @@ -127,7 +127,7 @@ namespace rexy::fmt::detail{ template constexpr void dynamic_format_specs_handler::on_dynamic_width(It first, It last){ parse_ctx.check_arg_id(0); //just to make sure we aren't switching indexing modes - specs.dyn_width.name = {first, last - first}; + specs.dyn_width.name = {first, std::size_t(last - first)}; specs.width_type = dyn_type::string; } template @@ -147,7 +147,7 @@ namespace rexy::fmt::detail{ template constexpr void dynamic_format_specs_handler::on_dynamic_precision(It first, It last){ parse_ctx.check_arg_id(0); //just to make sure we aren't switching indexing modes - specs.dyn_precision.name = {first, last - first}; + specs.dyn_precision.name = {first, std::size_t(last - first)}; specs.precision_type = dyn_type::string; } template diff --git a/include/rexy/detail/format/storage.tpp b/include/rexy/detail/format/storage.tpp index 19dc5c5..0f6594a 100644 --- a/include/rexy/detail/format/storage.tpp +++ b/include/rexy/detail/format/storage.tpp @@ -76,16 +76,16 @@ namespace rexy::fmt::detail{ constexpr auto operator()(T) -> typename basic_format_arg::handle; constexpr auto operator()(std::unsigned_integral auto i){ if constexpr(sizeof(i) <= sizeof(unsigned int)){ - return (unsigned int){}; + return (unsigned int)(0); }else{ - return (unsigned long long){}; + return (unsigned long long)(0); } } constexpr auto operator()(std::signed_integral auto i){ if constexpr(sizeof(i) <= sizeof(int)){ - return int{}; + return int(0); }else{ - return (long long){}; + return (long long)(0); } } template diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp index fe5003b..5707525 100644 --- a/include/rexy/string_base.hpp +++ b/include/rexy/string_base.hpp @@ -366,7 +366,7 @@ namespace rexy{ using const_reverse_iterator = typename string_base::const_reverse_iterator; using allocator_type = Alloc; - static constexpr size_type npos = size_type{-1}; + static constexpr size_type npos = size_type(-1); private: REXY_CPP20_CONSTEXPR void _copy_construct_string(const_pointer data, size_type len, size_type cap) diff --git a/include/rexy/string_base.tpp b/include/rexy/string_base.tpp index a99a031..d9c54d6 100644 --- a/include/rexy/string_base.tpp +++ b/include/rexy/string_base.tpp @@ -271,7 +271,7 @@ namespace rexy{ template REXY_CPP20_CONSTEXPR basic_string::basic_string(size_type cap) noexcept(is_nothrow_allocator_v): - basic_string(size_type{0}, cap){} + basic_string(size_type(0), cap){} template REXY_CPP20_CONSTEXPR basic_string::basic_string(size_type len, size_type cap) noexcept(is_nothrow_allocator_v) @@ -289,7 +289,7 @@ namespace rexy{ template REXY_CPP20_CONSTEXPR basic_string::basic_string(InputIt start, InputIt fin) noexcept(is_nothrow_allocator_v): - basic_string(nullptr, size_type{fin - start}) + basic_string(nullptr, size_type(fin - start)) { auto raw = this->get_pointer(); size_type i = 0; @@ -547,7 +547,7 @@ namespace rexy{ const size_type len = last - first; size_type count = 0; for(auto it = first2;count < len && it != last2;++count,++it); - return _replace_impl(size_type{first - this->begin()}, len, first2, count); + return _replace_impl(size_type(first - this->begin()), len, first2, count); } template constexpr auto basic_string::replace(size_type pos, size_type count, const_pointer cstr, size_type count2) -> basic_string&{ @@ -555,7 +555,7 @@ namespace rexy{ } template constexpr auto basic_string::replace(const_iterator first, const_iterator last, const_pointer cstr, size_type count) -> basic_string&{ - return _replace_impl(size_type{first - this->begin()}, size_type{last - first}, cstr, count); + return _replace_impl(size_type(first - this->begin()), size_type(last - first), cstr, count); } template constexpr auto basic_string::replace(size_type pos, size_type count, const_pointer cstr) -> basic_string&{ @@ -563,7 +563,7 @@ namespace rexy{ } template constexpr auto basic_string::replace(const_iterator first, const_iterator last, const_pointer cstr) -> basic_string&{ - return _replace_impl(size_type{first - this->begin()}, size_type{last - first}, cstr, rexy::strlen(cstr)); + return _replace_impl(size_type(first - this->begin()), size_type(last - first), cstr, rexy::strlen(cstr)); } template constexpr auto basic_string::replace(size_type pos, size_type count, size_type count2, value_type v) -> basic_string&{ @@ -571,11 +571,11 @@ namespace rexy{ } template constexpr auto basic_string::replace(const_iterator first, const_iterator last, size_type count2, value_type v) -> basic_string&{ - return _replace_impl(size_type{first - this->begin()}, size_type{last - first}, detail::value_iterator_adapter{v}, count2); + return _replace_impl(size_type(first - this->begin()), size_type(last - first), detail::value_iterator_adapter{v}, count2); } template constexpr auto basic_string::replace(const_iterator first, const_iterator last, std::initializer_list list) -> basic_string&{ - return _replace_impl(size_type{first - this->begin()}, size_type{last - first}, list.begin(), list.size()); + return _replace_impl(size_type(first - this->begin()), size_type(last - first), list.begin(), list.size()); } template template @@ -589,7 +589,7 @@ namespace rexy{ constexpr auto basic_string::replace(const_iterator first, const_iterator last, const StringView& sv) -> std::enable_if_t> && !std::is_convertible_v,basic_string&> { - return _replace_impl(size_type{first - this->begin()}, size_type{last - first}, sv.begin(), sv.length()); + return _replace_impl(size_type(first - this->begin()), size_type(last - first), sv.begin(), sv.length()); } template template @@ -700,10 +700,10 @@ namespace rexy{ if(insert_count + len <= cap){ - auto* dest_ptr = this->data() + pos + insert_count; - const auto* src_ptr = this->data() + pos; + auto* dest_ptr = this->data() + len + insert_count - 1; + const auto* src_ptr = this->data() + pos + insert_count; for(size_type i = 0;i < after_pos_count;++i){ - *dest_ptr++ = *src_ptr++; + *dest_ptr-- = *src_ptr--; } dest_ptr = this->data() + pos; for(size_type i = 0;i < insert_count;++i){ @@ -763,7 +763,7 @@ namespace rexy{ } template template - REXY_CPP20_CONSTEXPR string_cat_expr::operator basic_string(void) + REXY_CPP20_CONSTEXPR string_cat_expr::operator basic_string::value_type,Alloc>(void) noexcept(std::is_nothrow_constructible, typename basic_string::size_type>::value && std::is_nothrow_invocable>,decltype(*this)>::value) { diff --git a/include/rexy/string_view.hpp b/include/rexy/string_view.hpp index 812e0f7..2f15f4b 100644 --- a/include/rexy/string_view.hpp +++ b/include/rexy/string_view.hpp @@ -46,7 +46,7 @@ namespace rexy{ using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - static constexpr size_type npos = size_type{-1}; + static constexpr size_type npos = size_type(-1); private: const_pointer m_data = nullptr; diff --git a/src/filerd.cpp b/src/filerd.cpp index 8ea30aa..82834df 100644 --- a/src/filerd.cpp +++ b/src/filerd.cpp @@ -46,14 +46,14 @@ namespace rexy{ tmp = ftell(m_fp); fseek(m_fp, 0, SEEK_END); ret = ftell(m_fp); - fseek(m_fp, tmp, SEEK_SET); + fseek(m_fp, long(tmp), SEEK_SET); return ret; } std::size_t filerd::position(void)const noexcept{ return ftell(m_fp); } void filerd::rewind(std::size_t pos)noexcept{ - fseek(m_fp, pos, SEEK_SET); + fseek(m_fp, long(pos), SEEK_SET); } filerd::operator FILE*(void)noexcept{ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9af46fa..0ee0803 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.0.2) project(rexylib_tests) set(INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../include) include_directories("${INCLUDE_PATH}") -add_compile_options(-Wall -Wextra -pedantic -std=c++20 -Wno-free-nonheap-object) + +set(CMAKE_CXX_STANDARD 20) + +if(MSVC) + add_compile_options("/Zc:__cplusplus" "/Wall") +else() + add_compile_options("-Wall" "-Wextra" "-pedantic") +endif() link_libraries(rexy) if(ENABLE_PROFILING) diff --git a/tests/format.cpp b/tests/format.cpp index 9bd129f..c518119 100644 --- a/tests/format.cpp +++ b/tests/format.cpp @@ -22,9 +22,9 @@ void test_fail(void){ #define PERFORM_TEST(desired, formt, ...) \ do{ \ - rexy::string str = rexy::format((formt) __VA_OPT__(,) __VA_ARGS__); \ - if(str != (desired)){ \ - test_fail(str, desired); \ + rexy::string str = rexy::format( (formt), __VA_ARGS__); \ + if(str != (desired) ){ \ + test_fail( (str), (desired) ); \ } \ }while(0) @@ -58,12 +58,6 @@ void do_brace_escapes(void){ void do_empty_format(void){ -do{ - rexy::string str = rexy::format("{}", 0); - if(str != "0"_sv){ - test_fail(str.c_str(), "0"_sv); - } -}while(0); PERFORM_TEST("0"_sv, "{}", 0); PERFORM_TEST("0"_sv, "{}", 0ul); PERFORM_TEST("0"_sv, "{}", short{0});