From c5851a8161938798c5594a66420cb814fea92711 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Mon, 17 Apr 2017 12:26:38 -0700 Subject: [PATCH] Turn warnings into errors (#488) --- tests/CMakeLists.txt | 6 +++--- tests/at_tests.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 40c46d5..b56cc26 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,15 +18,15 @@ add_definitions(-DGSL_THROW_ON_CONTRACT_VIOLATION) if(MSVC) # has the support we need # remove unnecessary warnings about unchecked iterators add_definitions(-D_SCL_SECURE_NO_WARNINGS) - add_compile_options(/EHsc /W4) + add_compile_options(/EHsc /W4 /WX) else() include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(COMPILER_SUPPORTS_CXX14) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++14 -O3 -Wall -Wextra -Wpedantic -Wno-missing-braces -Wconversion -Wsign-conversion -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Woverloaded-virtual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++14 -Werror -Wall -Wextra -Wpedantic -Wno-missing-braces -Wconversion -Wsign-conversion -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Woverloaded-virtual") elseif(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++11 -O3 -Wall -Wextra -Wpedantic -Wno-missing-braces -Wconversion -Wsign-conversion -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Woverloaded-virtual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++11 -Werror -Wall -Wextra -Wpedantic -Wno-missing-braces -Wconversion -Wsign-conversion -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Woverloaded-virtual") else() message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() diff --git a/tests/at_tests.cpp b/tests/at_tests.cpp index 79f8ddd..db89c34 100644 --- a/tests/at_tests.cpp +++ b/tests/at_tests.cpp @@ -45,8 +45,8 @@ SUITE(at_tests) const std::array& c_a = a; for (int i = 0; i < 4; ++i) { - CHECK(&gsl::at(a, i) == &a[i]); - CHECK(&gsl::at(c_a, i) == &a[i]); + CHECK(&gsl::at(a, i) == &a[static_cast(i)]); + CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]); } CHECK_THROW(gsl::at(a, -1), fail_fast); @@ -61,8 +61,8 @@ SUITE(at_tests) const std::vector& c_a = a; for (int i = 0; i < 4; ++i) { - CHECK(&gsl::at(a, i) == &a[i]); - CHECK(&gsl::at(c_a, i) == &a[i]); + CHECK(&gsl::at(a, i) == &a[static_cast(i)]); + CHECK(&gsl::at(c_a, i) == &a[static_cast(i)]); } CHECK_THROW(gsl::at(a, -1), fail_fast); @@ -87,7 +87,7 @@ SUITE(at_tests) } } -#if !defined(_MSC_VER) || (defined(__clang__) || _MSC_VER >= 1910) +#if !defined(_MSC_VER) || defined(__clang__) || _MSC_VER >= 1910 static constexpr bool test_constexpr() { int a1[4] = { 1, 2, 3, 4 }; @@ -98,7 +98,9 @@ static constexpr bool test_constexpr() for (int i = 0; i < 4; ++i) { if (&gsl::at(a1, i) != &a1[i]) return false; if (&gsl::at(c_a1, i) != &a1[i]) return false; - if (&gsl::at(c_a2, i) != &c_a2[i]) return false; + // requires C++17: + // if (&gsl::at(a2, i) != &a2[static_cast(i)]) return false; + if (&gsl::at(c_a2, i) != &c_a2[static_cast(i)]) return false; if (gsl::at({1,2,3,4}, i) != i+1) return false; }