Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile C++20 in msvc #17

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 30 additions & 75 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,26 @@ image: Visual Studio 2019
environment:
matrix:

- compiler: msvc-16-seh
generator: "Visual Studio 16 2019"
genarch: -A Win32
configuration: Debug

- compiler: msvc-16-seh
generator: "Visual Studio 16 2019"
genarch: -A x64
configuration: Debug

- compiler: msvc-16-seh
generator: "Visual Studio 16 2019"
genarch: -A Win32
configuration: Release

- compiler: msvc-16-seh
generator: "Visual Studio 16 2019"
genarch: -A x64
configuration: Release


- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
compiler: msvc-15-seh
generator: "Visual Studio 15 2017"
configuration: Debug

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
compiler: msvc-15-seh
generator: "Visual Studio 15 2017 Win64"
configuration: Debug

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
compiler: msvc-15-seh
generator: "Visual Studio 15 2017"
configuration: Release

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
compiler: msvc-15-seh
generator: "Visual Studio 15 2017 Win64"
configuration: Release


#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
# compiler: msvc-14-seh
# generator: "Visual Studio 14 2015"
# configuration: Debug

#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
# compiler: msvc-14-seh
# generator: "Visual Studio 14 2015 Win64"
# configuration: Debug

#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
# compiler: msvc-14-seh
# generator: "Visual Studio 14 2015"
# configuration: Release

#- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
# compiler: msvc-14-seh
# generator: "Visual Studio 14 2015 Win64"
# configuration: Release

- {GEN: Visual Studio 16 2019, ARCH: -A x64, CFG: Debug, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A Win32, CFG: Debug, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A x64, CFG: Release, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A Win32, CFG: Release, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A x64, STD: -D C4_CXX_STANDARD=20, CFG: Debug, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A x64, STD: -D C4_CXX_STANDARD=17, CFG: Debug, compiler: msvc-16-seh}
- {GEN: Visual Studio 16 2019, ARCH: -A x64, STD: -D C4_CXX_STANDARD=14, CFG: Debug, compiler: msvc-16-seh}

- {GEN: Visual Studio 15 2017 Win64, CFG: Debug, APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017, compiler: msvc-15-seh}
- {GEN: Visual Studio 15 2017, CFG: Debug, APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017, compiler: msvc-15-seh}
- {GEN: Visual Studio 15 2017 Win64, CFG: Release, APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017, compiler: msvc-15-seh}
- {GEN: Visual Studio 15 2017, CFG: Release, APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017, compiler: msvc-15-seh}

#- compiler: gcc-5.3.0-posix
# generator: "MinGW Makefiles"
# GEN: "MinGW Makefiles"
# cxx_path: 'C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin'
# APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# configuration: Quicktest
# CFG: Quicktest
# externconfig: Debug
# cmkargs: "-DC4STL_PEDANTIC=ON -DC4STL_WERROR=ON"


matrix:
fast_finish: true
Expand All @@ -87,30 +37,31 @@ install:
- cmake --version

build_script:
- echo %generator%
- echo %genarch%
- echo %configuration%
- echo %GEN%
- echo %ARCH%
- echo %CFG%
- echo %STD%
- set NUM_JOBS=3
- set PROJ_DIR=%cd%
- set BUILD_DIR=%PROJ_DIR%\build
- set INSTALL_DIR=%PROJ_DIR%\install
- set C4_EXTERN_DIR=%BUILD_DIR%\extern
- md %BUILD_DIR%
- md %BUILD_DIR%\static %BUILD_DIR%\shared %BUILD_DIR%\extern
- cmake -S %PROJ_DIR% -B %BUILD_DIR%\static -DC4CORE_DEV=ON -G "%generator%" %genarch% "-DCMAKE_BUILD_TYPE=%configuration%" "-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%\static" -DBUILD_SHARED_LIBS=OFF
- cmake -S %PROJ_DIR% -B %BUILD_DIR%\shared -DC4CORE_DEV=ON -G "%generator%" %genarch% "-DCMAKE_BUILD_TYPE=%configuration%" "-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%\shared" -DBUILD_SHARED_LIBS=ON
- cmake -S %PROJ_DIR% -B %BUILD_DIR%\static %STD% -DC4CORE_DEV=ON -G "%GEN%" %ARCH% "-DCMAKE_BUILD_TYPE=%CFG%" "-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%\static" -DBUILD_SHARED_LIBS=OFF
- cmake -S %PROJ_DIR% -B %BUILD_DIR%\shared %STD% -DC4CORE_DEV=ON -G "%GEN%" %ARCH% "-DCMAKE_BUILD_TYPE=%CFG%" "-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%\shared" -DBUILD_SHARED_LIBS=ON
- cmake --build %BUILD_DIR%\static --config %configuration% --target test-build --parallel %NUM_JOBS%
- cmake --build %BUILD_DIR%\shared --config %configuration% --target test-build --parallel %NUM_JOBS%

test_script:
- cmake --build %BUILD_DIR%\static --config %configuration% --target test
- cmake --build %BUILD_DIR%\shared --config %configuration% --target test

artifacts:
- path: '_build/CMakeFiles/*.log'
name: logs
- path: '_build/Testing/**/*.xml'
name: test_results
#artifacts:
# - path: '_build/CMakeFiles/*.log'
# name: logs
# - path: '_build/Testing/**/*.xml'
# name: test_results

skip_commits:
files:
Expand All @@ -123,5 +74,9 @@ skip_commits:
- .ci/Vagrant*
- bm/html/*
- doc/*
- img/*
- CHANGELOG.md
- CONTRIBUTING.md
- LICENSE.txt
- README.*
- ROADMAP.*
2 changes: 1 addition & 1 deletion cmake
Submodule cmake updated 1 files
+1 −1 c4Project.cmake
25 changes: 20 additions & 5 deletions src/c4/language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
# if (!defined(_MSVC_LANG))
# error _MSVC not defined
# endif
# if _MSVC_LANG >= 201703L
# if _MSVC_LANG >= 201705L
# define C4_CPP 20
# define C4_CPP20
# elif _MSVC_LANG == 201703L
# define C4_CPP 17
# define C4_CPP17
# elif _MSVC_LANG >= 201402L
Expand All @@ -41,7 +44,10 @@
# endif
# endif
# elif defined(__INTEL_COMPILER) // https://software.intel.com/en-us/node/524490
# ifdef __INTEL_CXX17_MODE__ // not sure about this
# ifdef __INTEL_CXX20_MODE__ // not sure about this
# define C4_CPP 20
# define C4_CPP20
# elif defined __INTEL_CXX17_MODE__ // not sure about this
# define C4_CPP 17
# define C4_CPP17
# elif defined __INTEL_CXX14_MODE__ // not sure about this
Expand All @@ -59,6 +65,9 @@
# endif
# if __cplusplus == 1
# error cannot handle __cplusplus==1
# elif __cplusplus >= 202002L
# define C4_CPP 20
# define C4_CPP20
# elif __cplusplus >= 201703L
# define C4_CPP 17
# define C4_CPP17
Expand All @@ -73,7 +82,9 @@
# endif
# endif
#else
# ifdef C4_CPP == 17
# ifdef C4_CPP == 20
# define C4_CPP20
# elif C4_CPP == 17
# define C4_CPP17
# elif C4_CPP == 14
# define C4_CPP14
Expand All @@ -83,11 +94,15 @@
# define C4_CPP98
# error C++ lesser than C++11 not supported
# else
# error C4_CPP must be one of 17, 14, 11, 98
# error C4_CPP must be one of 20, 17, 14, 11, 98
# endif
#endif

#ifdef C4_CPP17
#ifdef C4_CPP20
# define C4_CPP17
# define C4_CPP14
# define C4_CPP11
#elif defined(C4_CPP17)
# define C4_CPP14
# define C4_CPP11
#elif defined(C4_CPP14)
Expand Down
9 changes: 8 additions & 1 deletion src/c4/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ struct cref_uses_val
enum { value = (
std::is_scalar<T>::value
||
(std::is_pod<T>::value && sizeof(T) <= sizeof(size_t))) };
(
#if C4_CPP >= 20
(std::is_trivially_copyable<T>::value && std::is_standard_layout<T>::value)
#else
std::is_pod<T>::value
#endif
&&
sizeof(T) <= sizeof(size_t))) };
};
/** utility macro to override the default behaviour for c4::fastcref<T>
@see fastcref */
Expand Down
85 changes: 25 additions & 60 deletions test/test_charconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,77 +877,42 @@ TEST(to_chars, std_string)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

TEST(to_chars, trimmed_fit_int)
// test that no characters are trimmed at the end of
// the number due to printf-based implementations
// needing space for the \0
template<class T>
void test_trimmed_fit(T v, csubstr expected)
{
// test that no characters are trimmed at the end of
// the number due to printf-based implementations
// needing space for the \0
int v = 12345678;
char buf[128];
substr sp(buf);
size_t sz = to_chars(sp, v);
sp = sp.left_of(sz);
EXPECT_EQ(sp, "12345678"); // ehemm.
char buf2[8+1];
C4_ASSERT(sizeof(buf2) == sz+1);
substr sp2(buf2, sizeof(buf2)); // make sure it spans the whole buffer
sp2 = to_chars_sub(sp2, v);
EXPECT_EQ(sp2, sp); // ehemm.
char buf_[128] = {};
char buf2_[128] = {};
substr buf(buf_);
substr buf2(buf_);
ASSERT_GE(buf.len, expected.len);
ASSERT_GE(buf2.len, expected.len);
csubstr result = to_chars_sub(buf, v);
EXPECT_EQ(result, expected);
csubstr result2 = to_chars_sub(buf2.sub(result.len), v);
EXPECT_EQ(result2, result);
std::string str;
catrs(&str, v);
EXPECT_EQ(sp, to_csubstr(str)); // ehemm.
EXPECT_EQ(result, to_csubstr(str));
}

TEST(to_chars, trimmed_fit_int)
{
test_trimmed_fit(12345678, "12345678");
}

TEST(to_chars, trimmed_fit_float)
{
// test that no characters are trimmed at the end of
// the number due to printf-based implementations
// needing space for the \0
float v = 1024.1568f;
char buf[128];
substr sp(buf);
size_t sz = to_chars(sp, v);
sp = sp.left_of(sz);
#if 1 || C4CORE_HAVE_STD_TOCHARS // WORK_IN PROGRESS
EXPECT_EQ(sp, "1024.16"); // ehemm.
char buf2[7 + 1];
#else
EXPECT_EQ(sp, "1024.1569"); // ehemm.
char buf2[9 + 1];
#endif
C4_ASSERT(sizeof(buf2) == sz+1);
substr sp2(buf2, sizeof(buf2)); // make sure it spans the whole buffer
sp2 = to_chars_sub(sp2, v);
EXPECT_EQ(sp2, sp); // ehemm.
std::string str;
catrs(&str, v);
EXPECT_EQ(sp, to_csubstr(str)); // ehemm.
test_trimmed_fit(0.375f, "0.375");
test_trimmed_fit(12.375f, "12.375");
}

TEST(to_chars, trimmed_fit_double)
{
// test that no characters are trimmed at the end of
// the number due to printf-based implementations
// needing space for the \0
double v = 1024.1568;
char buf[128];
substr sp(buf);
size_t sz = to_chars(sp, v);
sp = sp.left_of(sz);
#if 1 || C4CORE_HAVE_STD_TOCHARS // WORK_IN PROGRESS
EXPECT_EQ(sp, "1024.16"); // ehemm.
char buf2[7 + 1];
#else
EXPECT_EQ(sp, "1024.1568"); // ehemm.
char buf2[9 + 1];
#endif
C4_ASSERT(sizeof(buf2) == sz+1);
substr sp2(buf2, sizeof(buf2)); // make sure it spans the whole buffer
sp2 = to_chars_sub(sp2, v);
EXPECT_EQ(sp2, sp); // ehemm.
std::string str;
catrs(&str, v);
EXPECT_EQ(sp, to_csubstr(str)); // ehemm.
test_trimmed_fit(0.375, "0.375");
test_trimmed_fit(12.375, "12.375");
}


Expand Down