Fix MSVC build failure
This commit is contained in:
parent
1165165657
commit
2f64eb40f0
@ -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()
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
#include <cstddef> //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
|
||||
|
||||
@ -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<class Char>
|
||||
|
||||
@ -328,9 +328,9 @@ namespace rexy::fmt::detail{
|
||||
template<class Char, class OutIt>
|
||||
constexpr OutIt perform_localized_integer_write(OutIt out, const char* start, const char* last, const std::locale& loc){
|
||||
const auto& facet = std::use_facet<std::numpunct<Char>>(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);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ namespace rexy::fmt::detail{
|
||||
}
|
||||
template<class It, class... Args>
|
||||
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<It, 0, Args...>(first, last);
|
||||
|
||||
@ -127,7 +127,7 @@ namespace rexy::fmt::detail{
|
||||
template<class It>
|
||||
constexpr void dynamic_format_specs_handler<ParseCtx>::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<class ParseCtx>
|
||||
@ -147,7 +147,7 @@ namespace rexy::fmt::detail{
|
||||
template<class It>
|
||||
constexpr void dynamic_format_specs_handler<ParseCtx>::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<class ParseCtx>
|
||||
|
||||
@ -76,16 +76,16 @@ namespace rexy::fmt::detail{
|
||||
constexpr auto operator()(T) -> typename basic_format_arg<Context>::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<std::floating_point T>
|
||||
|
||||
@ -366,7 +366,7 @@ namespace rexy{
|
||||
using const_reverse_iterator = typename string_base<Char>::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)
|
||||
|
||||
@ -271,7 +271,7 @@ namespace rexy{
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type cap)
|
||||
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||
basic_string(size_type{0}, cap){}
|
||||
basic_string(size_type(0), cap){}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type len, size_type cap)
|
||||
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||
@ -289,7 +289,7 @@ namespace rexy{
|
||||
template<class InputIt, class Enable>
|
||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(InputIt start, InputIt fin)
|
||||
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||
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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const_pointer cstr, size_type count2) -> basic_string&{
|
||||
@ -555,7 +555,7 @@ namespace rexy{
|
||||
}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const_pointer cstr) -> basic_string&{
|
||||
@ -563,7 +563,7 @@ namespace rexy{
|
||||
}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, size_type count2, value_type v) -> basic_string&{
|
||||
@ -571,11 +571,11 @@ namespace rexy{
|
||||
}
|
||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, std::initializer_list<value_type> 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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
template<class StringView>
|
||||
@ -589,7 +589,7 @@ namespace rexy{
|
||||
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const StringView& sv) ->
|
||||
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,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<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
template<class StringView>
|
||||
@ -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<class Left, class Right>
|
||||
template<REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
REXY_CPP20_CONSTEXPR string_cat_expr<Left,Right>::operator basic_string<value_type,Alloc>(void)
|
||||
REXY_CPP20_CONSTEXPR string_cat_expr<Left,Right>::operator basic_string<typename string_cat_expr<Left,Right>::value_type,Alloc>(void)
|
||||
noexcept(std::is_nothrow_constructible<basic_string<value_type,Alloc>, typename basic_string<value_type,Alloc>::size_type>::value &&
|
||||
std::is_nothrow_invocable<detail::string_appender<basic_string<value_type,Alloc>>,decltype(*this)>::value)
|
||||
{
|
||||
|
||||
@ -46,7 +46,7 @@ namespace rexy{
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr size_type npos = size_type{-1};
|
||||
static constexpr size_type npos = size_type(-1);
|
||||
|
||||
private:
|
||||
const_pointer m_data = nullptr;
|
||||
|
||||
@ -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{
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user