From 1843b1739e30393f9a05693d4c4176eb7fe0aa83 Mon Sep 17 00:00:00 2001 From: galik Date: Tue, 16 Feb 2016 00:57:04 +0000 Subject: [PATCH 1/5] Fix: Issue: #267 gsl::fail_fast only defined for one configuration --- include/gsl_assert.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/gsl_assert.h b/include/gsl_assert.h index 81cfd13..51e8ab6 100644 --- a/include/gsl_assert.h +++ b/include/gsl_assert.h @@ -20,6 +20,7 @@ #define GSL_CONTRACTS_H #include +#include // // There are three configuration options for this GSL implementation's behavior @@ -42,10 +43,6 @@ // GSL.assert: assertions // -#if defined(GSL_THROW_ON_CONTRACT_VIOLATION) - -#include - namespace gsl { struct fail_fast : public std::runtime_error @@ -54,6 +51,8 @@ struct fail_fast : public std::runtime_error }; } +#if defined(GSL_THROW_ON_CONTRACT_VIOLATION) + #define Expects(cond) if (!(cond)) \ throw gsl::fail_fast("GSL: Precondition failure at " __FILE__ ": " GSL_STRINGIFY(__LINE__)); #define Ensures(cond) if (!(cond)) \ From 32d00796ad530d202dcbdaf817d47a2405b31301 Mon Sep 17 00:00:00 2001 From: Sergiy Oryekhov Date: Wed, 23 Mar 2016 16:42:35 -0700 Subject: [PATCH 2/5] Adding unittest-cpp as a submodule. --- .gitignore | 1 - .gitmodules | 3 +++ tests/CMakeLists.txt | 4 ++-- tests/unittest-cpp | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 tests/unittest-cpp diff --git a/.gitignore b/.gitignore index ea47eb3..d452689 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -tests/unittest-cpp CMakeFiles tests/CMakeFiles tests/Debug diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d9229ae --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/unittest-cpp"] + path = tests/unittest-cpp + url = https://github.com/Microsoft/unittest-cpp.git diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7990ec3..66516fe 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,8 +28,8 @@ else() endif() endif() -if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp) - message(FATAL_ERROR "Could not find unittest-cpp enlistment. Please run 'git clone https://github.com/Microsoft/unittest-cpp.git unittest-cpp' in the tests directory") +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp/tests) + execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") endif() function(add_gsl_test name) diff --git a/tests/unittest-cpp b/tests/unittest-cpp new file mode 160000 index 0000000..dc6b908 --- /dev/null +++ b/tests/unittest-cpp @@ -0,0 +1 @@ +Subproject commit dc6b90838014ab985bf3cd74ac17ad9d00e1fbcb From 79030c55863d8a98fb67d549c747c9666b4ef2ec Mon Sep 17 00:00:00 2001 From: Sergiy Oryekhov Date: Wed, 23 Mar 2016 16:53:00 -0700 Subject: [PATCH 3/5] Moving submodule init before subdirectory. --- tests/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 66516fe..e6527da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8.7) project(GSLTests CXX) +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp/tests) + execute_process(COMMAND git submodule update --init WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +endif() + add_subdirectory(unittest-cpp) include_directories( @@ -28,10 +32,6 @@ else() endif() endif() -if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp/tests) - execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") -endif() - function(add_gsl_test name) add_executable(${name} ${name}.cpp ../include/gsl.h ../include/gsl_assert.h ../include/gsl_util.h ../include/span.h ../include/string_span.h) target_link_libraries(${name} UnitTest++) From 38d8a3f82dea1125068f301db6cf3f1944d8fc61 Mon Sep 17 00:00:00 2001 From: Sergiy Oryekhov Date: Thu, 24 Mar 2016 16:59:45 -0700 Subject: [PATCH 4/5] Updating travis script. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3c64230..3fed41b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,6 @@ install: before_script: - cd ${TRAVIS_BUILD_DIR} - - git clone --depth 1 https://github.com/Microsoft/unittest-cpp tests/unittest-cpp - cmake -H. -Bb -DCMAKE_CXX_COMPILER=$COMPILER -DCMAKE_INSTALL_PREFIX=$PWD/o -DCMAKE_BUILD_TYPE=$BUILD_TYPE - cmake --build b From a9f0ce2f77e4230275dc7a22f3bef351e251f29c Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Thu, 31 Mar 2016 12:01:07 -0700 Subject: [PATCH 5/5] Suppressed CppCoreCheck warnings. --- include/gsl_util.h | 6 +++++- include/span.h | 8 +++++++- include/string_span.h | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/gsl_util.h b/include/gsl_util.h index 316f2a1..edfcce4 100644 --- a/include/gsl_util.h +++ b/include/gsl_util.h @@ -31,6 +31,9 @@ #pragma push_macro("constexpr") #define constexpr +#pragma warning(push) +#pragma warning(disable: 4127) // conditional expression is constant + // MSVC 2013 workarounds #if _MSC_VER <= 1800 // noexcept is not understood @@ -40,7 +43,6 @@ // turn off some misguided warnings #pragma warning(push) #pragma warning(disable: 4351) // warns about newly introduced aggregate initializer behavior -#pragma warning(disable: 4127) // conditional expression is constant #endif // _MSC_VER <= 1800 @@ -131,6 +133,8 @@ constexpr typename Cont::value_type& at(Cont& cont, size_t index) #ifdef _MSC_VER +#pragma warning(pop) + #undef constexpr #pragma pop_macro("constexpr") diff --git a/include/span.h b/include/span.h index 31c26ad..a612983 100644 --- a/include/span.h +++ b/include/span.h @@ -37,10 +37,16 @@ #ifdef _MSC_VER -// turn off some warnings that are noisy about our Expects statements #pragma warning(push) + +// turn off some warnings that are noisy about our Expects statements #pragma warning(disable : 4127) // conditional expression is constant +// blanket turn off warnings from CppCoreCheck for now +// so people aren't annoyed by them when running the tool. +// more targeted suppressions will be added in a future update to the GSL +#pragma warning(disable: 26481 26482 26483 26485 26490 26491 26492 26493 26495) + // No MSVC does constexpr fully yet #pragma push_macro("constexpr") #define constexpr diff --git a/include/string_span.h b/include/string_span.h index 46bf2d4..fdcbf31 100644 --- a/include/string_span.h +++ b/include/string_span.h @@ -31,6 +31,14 @@ #pragma push_macro("constexpr") #define constexpr /* nothing */ +#pragma warning(push) + +// blanket turn off warnings from CppCoreCheck for now +// so people aren't annoyed by them when running the tool. +// more targeted suppressions will be added in a future update to the GSL +#pragma warning(disable: 26481 26482 26483 26485 26490 26491 26492 26493 26495) + + // VS 2013 workarounds #if _MSC_VER <= 1800 @@ -930,12 +938,14 @@ bool operator>=(const T& one, gsl::basic_string_span other) noexc } #endif -// VS 2013 workarounds #ifdef _MSC_VER +#pragma warning(pop) + #undef constexpr #pragma pop_macro("constexpr") +// VS 2013 workarounds #if _MSC_VER <= 1800 #ifndef GSL_THROW_ON_CONTRACT_VIOLATION