Skip to content

Commit

Permalink
Turn warnings into errors (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyCarter authored and Neil MacIntosh committed Apr 17, 2017
1 parent c2f953f commit c5851a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions tests/at_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ SUITE(at_tests)
const std::array<int, 4>& 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<std::size_t>(i)]);
CHECK(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}

CHECK_THROW(gsl::at(a, -1), fail_fast);
Expand All @@ -61,8 +61,8 @@ SUITE(at_tests)
const std::vector<int>& 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<std::size_t>(i)]);
CHECK(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}

CHECK_THROW(gsl::at(a, -1), fail_fast);
Expand All @@ -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 };
Expand All @@ -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<std::size_t>(i)]) return false;
if (&gsl::at(c_a2, i) != &c_a2[static_cast<std::size_t>(i)]) return false;
if (gsl::at({1,2,3,4}, i) != i+1) return false;
}

Expand Down

0 comments on commit c5851a8

Please sign in to comment.