Fix setting the C++ standard for Travis builds

This commit is contained in:
Thomas Schaub 2019-03-14 17:30:42 +01:00 committed by Thomas Schaub
parent b21c04c938
commit ec06013eb0
5 changed files with 40 additions and 9 deletions

View File

@ -206,7 +206,7 @@ matrix:
compiler: gcc
env:
- COMPILER=g++-8
- CXXFLAGS=-std=c++17
- CMAKE_OPTIONS=-DJSON_ForceCpp17=ON
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
@ -290,7 +290,7 @@ matrix:
compiler: clang
env:
- COMPILER=clang++-7
- CXXFLAGS=-std=c++1z
- CMAKE_OPTIONS=-DJSON_ForceCpp17=ON
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-7']

View File

@ -72,6 +72,10 @@ SOFTWARE.
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/json_fwd.hpp>
#if defined(JSON_HAS_CPP_17)
#include <string_view>
#endif
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@ -2863,9 +2867,9 @@ class basic_json
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914))
and not std::is_same<ValueType, typename std::string_view>::value
#endif
#if defined(JSON_HAS_CPP_17)
and not std::is_same<ValueType, typename std::string_view>::value
#endif
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
, int >::type = 0 >

View File

@ -12841,6 +12841,10 @@ class serializer
// #include <nlohmann/json_fwd.hpp>
#if defined(JSON_HAS_CPP_17)
#include <string_view>
#endif
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@ -15632,9 +15636,9 @@ class basic_json
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914))
and not std::is_same<ValueType, typename std::string_view>::value
#endif
#if defined(JSON_HAS_CPP_17)
and not std::is_same<ValueType, typename std::string_view>::value
#endif
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
, int >::type = 0 >

View File

@ -2,6 +2,7 @@ option(JSON_Sanitizer "Build test suite with Clang sanitizer" OFF)
option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
option(JSON_NoExceptions "Build test suite without exceptions" OFF)
option(JSON_Coverage "Build test suite with coverage information" OFF)
option(JSON_ForceCpp17 "Use C++17 standard" OFF)
if(JSON_Sanitizer)
message(STATUS "Building test suite with Clang sanitizer")
@ -85,7 +86,7 @@ if(MSVC)
# Disable warning C4566: character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)
# Disable warning C4996: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator <<': was declared deprecated
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4389 /wd4309 /wd4566 /wd4996")
# https://github.com/nlohmann/json/issues/1114
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
endif()
@ -104,6 +105,15 @@ foreach(file ${files})
CATCH_CONFIG_FAST_COMPILE
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
)
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
if (JSON_ForceCpp17)
message(FATAL_ERROR "Cannot force C++17 with this CMake version, you need at least version 3.8")
endif()
else()
if (JSON_ForceCpp17)
target_compile_features(${testcase} PRIVATE cxx_std_17)
endif()
endif()
target_compile_options(${testcase} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>

View File

@ -51,6 +51,20 @@ using nlohmann::json;
#include <string_view>
#endif
template<typename From, typename To>
struct is_implicitly_convertible
{
private:
template <typename C>
static std::true_type test(decltype(&C::operator To));
template <typename C>
static std::false_type test(...);
public:
static constexpr bool value = std::is_same<std::true_type, decltype(test<From>(nullptr))>::value;
};
TEST_CASE("value conversion")
{
SECTION("get an object (explicit)")
@ -480,8 +494,7 @@ TEST_CASE("value conversion")
#if defined(JSON_HAS_CPP_17)
SECTION("std::string_view")
{
std::string_view s = j;
CHECK(json(s) == j);
static_assert(!is_implicitly_convertible<decltype(j), std::string_view>::value);
}
#endif