Skip to content

Commit

Permalink
Merge pull request #382 from beached/v3
Browse files Browse the repository at this point in the history
Fixed some issues with MSVC and /permissive
  • Loading branch information
beached authored May 13, 2023
2 parents 6d2f8f5 + 540b630 commit 9f35418
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ jobs:
cpp_version: [ 17, 20 ]
build_type: [ Debug, Release ]
os: [ ubuntu-20.04, ubuntu-22.04 ]
toolset: [ g++-9, g++-10, g++-11, g++-12, clang++-8, clang++-9, clang++-10, clang++-11, clang++-12, clang++-13, clang++-14 ]
toolset: [ g++-9, g++-10, g++-11, g++-12, clang++-9, clang++-10, clang++-11, clang++-12, clang++-13, clang++-14, clang++-15, clang++-16 ]
exclude:
- toolset: clang++-8
cpp_version: 20
- toolset: clang++-9
cpp_version: 17
build_type: Debug
Expand Down Expand Up @@ -75,6 +73,8 @@ jobs:
sudo apt-add-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal main'
sudo apt-add-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main'
sudo apt-add-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main'
sudo apt-add-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main'
sudo apt-add-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main'
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install ninja-build libunwind-dev
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cmake_minimum_required( VERSION 3.14 )

project( "daw-json-link"
VERSION "3.16.0"
VERSION "3.17.0"
DESCRIPTION "Static JSON parsing in C++"
HOMEPAGE_URL "https://github.com/beached/daw_json_link"
LANGUAGES C CXX )
Expand Down
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include( FetchContent )
FetchContent_Declare(
daw_header_libraries
GIT_REPOSITORY https://github.com/beached/header_libraries.git
GIT_TAG v2.87.1
GIT_TAG v2.92.0
)

FetchContent_Declare(
Expand Down
30 changes: 12 additions & 18 deletions include/daw/json/impl/daw_json_parse_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ namespace daw::json {
using T = typename JsonClass::parse_to_t;
using Constructor = typename JsonClass::constructor_t;
static_assert( has_json_data_contract_trait_v<T>, "Unexpected type" );
using must_exist = daw::constant<(
json_details::all_json_members_must_exist_v<T, ParseState>
? AllMembersMustExist::yes
: AllMembersMustExist::no )>;
using must_exist =
daw::constant<( all_json_members_must_exist_v<T, ParseState>
? AllMembersMustExist::yes
: AllMembersMustExist::no )>;

parse_state.trim_left( );
// TODO, use member name
Expand All @@ -205,8 +205,7 @@ namespace daw::json {

if constexpr( sizeof...( JsonMembers ) == 0 ) {
// Clang-CL with MSVC has issues if we don't do empties this way
class_cleanup_now<
json_details::all_json_members_must_exist_v<T, ParseState>>(
class_cleanup_now<all_json_members_must_exist_v<T, ParseState>>(
parse_state, old_class_pos );

if constexpr( should_construct_explicitly_v<Constructor, T,
Expand All @@ -233,8 +232,7 @@ namespace daw::json {
/// on NRVO. This requires on_exit_success that on some platforms
/// can cost a bunch because it checks std::uncaught_exceptions
auto const run_after_parse = daw::on_exit_success( [&] {
class_cleanup_now<
json_details::all_json_members_must_exist_v<T, ParseState>>(
class_cleanup_now<all_json_members_must_exist_v<T, ParseState>>(
parse_state, old_class_pos );
} );
(void)run_after_parse;
Expand All @@ -258,8 +256,7 @@ namespace daw::json {
Is, traits::nth_type<Is, JsonMembers...>, must_exist::value,
NeedClassPositions::value>( parse_state, known_locations )... };

class_cleanup_now<
json_details::all_json_members_must_exist_v<T, ParseState>>(
class_cleanup_now<all_json_members_must_exist_v<T, ParseState>>(
parse_state, old_class_pos );
return result;
} else {
Expand All @@ -269,8 +266,7 @@ namespace daw::json {
must_exist::value, NeedClassPositions::value>(
parse_state, known_locations )... } );

class_cleanup_now<
json_details::all_json_members_must_exist_v<T, ParseState>>(
class_cleanup_now<all_json_members_must_exist_v<T, ParseState>>(
parse_state, old_class_pos );
return result;
}
Expand Down Expand Up @@ -307,10 +303,9 @@ namespace daw::json {

if constexpr( is_pinned_type_v<typename JsonClass::parse_to_t> ) {
auto const run_after_parse = daw::on_exit_success( [&] {
ordered_class_cleanup<
json_details::all_json_members_must_exist_v<T, ParseState>,
ParseState, decltype( old_class_pos )>( parse_state,
old_class_pos );
ordered_class_cleanup<all_json_members_must_exist_v<T, ParseState>,
ParseState, decltype( old_class_pos )>(
parse_state, old_class_pos );
} );
(void)run_after_parse;
if constexpr( should_construct_explicitly_v<Constructor, T,
Expand All @@ -336,8 +331,7 @@ namespace daw::json {
template_arg<JsonMembers>, current_idx, parse_state )... } );
}
}( );
if constexpr( json_details::all_json_members_must_exist_v<
T, ParseState> ) {
if constexpr( all_json_members_must_exist_v<T, ParseState> ) {
parse_state.trim_left( );
daw_json_assert_weak( parse_state.front( ) == ']',
ErrorReason::UnknownMember, parse_state );
Expand Down
2 changes: 1 addition & 1 deletion include/daw/json/impl/daw_json_parse_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ namespace daw::json {
"Detection failure" );
static_assert( not is_nonesuch_v<rcvref_type>, "Detection failure" );
return daw::traits::identity<type>{ };
} else if constexpr( json_details::is_a_json_type_v<T> ) {
} else if constexpr( is_a_json_type_v<T> ) {
static_assert( not std::is_same_v<T, void> );
using type =
typename std::conditional_t<is_json_class_map_v<T>,
Expand Down
4 changes: 0 additions & 4 deletions include/daw/json/impl/daw_json_parse_iso8601_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@ namespace daw::json {
daw_json_error( ErrorReason::InvalidTimestamp ); // Invalid month
}
}
static_assert(
short_day_of_week(
std::chrono::time_point<std::chrono::system_clock,
std::chrono::milliseconds>( ) ) == "Thu" );

namespace datetime_details {
constexpr std::uint_least32_t month2num( std::string_view ts ) {
Expand Down
12 changes: 5 additions & 7 deletions include/daw/json/impl/daw_json_parse_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ namespace daw::json {
}

template<typename JsonMember, typename ParseState>
static constexpr auto find_index( ParseState const & parse_state ) {
static constexpr auto find_index( ParseState const &parse_state ) {
using tag_member = typename JsonMember::tag_member;
using class_wrapper_t = typename JsonMember::tag_member_class_wrapper;

Expand Down Expand Up @@ -1132,10 +1132,9 @@ namespace daw::json {
std::size_t class_idx = 0;
if constexpr( is_pinned_type_v<typename JsonMember::parse_to_t> ) {
auto const run_after_parse = daw::on_exit_success( [&] {
ordered_class_cleanup<json_details::all_json_members_must_exist_v<
JsonMember, ParseState>,
ParseState, decltype( old_class_pos )>(
parse_state, old_class_pos );
ordered_class_cleanup<
all_json_members_must_exist_v<JsonMember, ParseState>, ParseState,
decltype( old_class_pos )>( parse_state, old_class_pos );
} );
(void)run_after_parse;
if constexpr( should_construct_explicitly_v<Constructor, tuple_t,
Expand All @@ -1159,8 +1158,7 @@ namespace daw::json {
class_idx )... } );
}
}( );
if constexpr( json_details::all_json_members_must_exist_v<
tuple_t, ParseState> ) {
if constexpr( all_json_members_must_exist_v<tuple_t, ParseState> ) {
parse_state.trim_left( );
daw_json_assert_weak( parse_state.front( ) == ']',
ErrorReason::UnknownMember, parse_state );
Expand Down
3 changes: 1 addition & 2 deletions include/daw/json/impl/daw_json_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ namespace daw::json {
/// Detect if T follows the tuple protocol
/// \tparam T
template<typename T>
inline constexpr bool is_tuple_v =
daw::is_detected_v<json_details::tuple_test, T>;
inline constexpr bool is_tuple_v = daw::is_detected_v<tuple_test, T>;

template<typename T>
using unwrapped_t = concepts::nullable_value_type_t<T>;
Expand Down
4 changes: 2 additions & 2 deletions tests/cmake/test_compiler_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQU
if( MSVC )
message( STATUS "Clang-CL ${CMAKE_CXX_COMPILER_VERSION} detected" )
add_definitions( -DNOMINMAX -DD_WIN32_WINNT=0x0601 -D_CRT_SECURE_NO_WARNINGS )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG /permissive- /EHsc -D_LIBCPP_ENABLE_ASSERTIONS=1" )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG /permissive- /EHsc -D_LIBCPP_ENABLE_ASSERTIONS=1" )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 -DNDEBUG /permissive- /EHsc" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 -DNDEBUG /permissive- /EHsc" )
if( DAW_WERROR )
Expand All @@ -31,7 +31,7 @@ if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQU
-pedantic
-Weverything
-ftemplate-backtrace-limit=0
-Wincompatible-pointer-types-discards-qualifiers
-Wincompatible-pointer-types-discards-qualifiers
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-covered-switch-default
Expand Down
10 changes: 10 additions & 0 deletions tests/src/daw_json_link_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,16 @@ int main( int, char ** ) {
std::cout << "round trip of " << ts2 << " became " << parsed_dte2_str
<< '\n';
ensure( ts2 == parsed_dte2_str );
#if DAW_HAS_CLANG_VER_GTE( 9, 0 )
static_assert( daw::json::datetime::short_day_of_week(
std::chrono::time_point<std::chrono::system_clock,
std::chrono::milliseconds>( ) ) ==
"Thu" );
#else
ensure( daw::json::datetime::short_day_of_week(
std::chrono::time_point<std::chrono::system_clock,
std::chrono::milliseconds>( ) ) == "Thu" );
#endif

#if defined( __cpp_lib_char8_t )
#if __cpp_lib_char8_t >= 201907L
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test_details_parse_value_real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool test_bad_real_untrusted2( ) {
#define do_fail_test( ... ) \
do { \
try { \
daw::expecting_message( __VA_ARGS__, "" #__VA_ARGS__ ); \
daw::expecting_message( (__VA_ARGS__), "" #__VA_ARGS__ ); \
} catch( daw::json::json_exception const & ) { break; } \
std::cerr << "Expected exception, but none thrown in '" \
<< "" #__VA_ARGS__ << "'\n"; \
Expand Down

0 comments on commit 9f35418

Please sign in to comment.