mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Turn warnings into errors (#488)
This commit is contained in:
parent
c2f953f2eb
commit
c5851a8161
@ -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()
|
||||
|
@ -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);
|
||||
@ -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);
|
||||
@ -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<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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user