Merge pull request #184 from neilmacintosh/dev/neilmac/warnings

Turning on max warning levels for compilation.
This commit is contained in:
Neil MacIntosh 2015-11-12 19:35:36 -08:00
commit ee731055da
6 changed files with 44 additions and 21 deletions

View File

@ -55,6 +55,7 @@
// turn off some misguided warnings // turn off some misguided warnings
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4351) // warns about newly introduced aggregate initializer behavior #pragma warning(disable: 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable: 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800 #endif // _MSC_VER <= 1800

View File

@ -14,6 +14,7 @@ add_definitions(-DGSL_THROWS_FOR_TESTING)
if(MSVC14 OR MSVC12) # has the support we need if(MSVC14 OR MSVC12) # has the support we need
# remove unnecessary warnings about unchecked iterators # remove unnecessary warnings about unchecked iterators
add_definitions(-D_SCL_SECURE_NO_WARNINGS) add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_compile_options(/W4)
else() else()
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
@ -25,6 +26,7 @@ else()
else() else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
add_compile_options(-Wall -Wno-missing-braces)
endif() endif()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp) if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest-cpp)

View File

@ -32,7 +32,9 @@ SUITE(bounds_test)
{ {
for (auto point : static_bounds<dynamic_range, 3, 4 > { 2 }) for (auto point : static_bounds<dynamic_range, 3, 4 > { 2 })
{ {
for (decltype(point)::size_type j = 0; j < decltype(point)::rank; j++) for (decltype(point)::size_type j = 0;
j < static_cast<decltype(point)::size_type>(decltype(point)::rank);
j++)
{ {
use(j); use(j);
use(point[j]); use(point[j]);
@ -44,6 +46,7 @@ SUITE(bounds_test)
{ {
static_bounds<3, 4, 5> b; static_bounds<3, 4, 5> b;
auto a = b.slice(); auto a = b.slice();
(void)a;
static_bounds<4, dynamic_range, 2> x{ 4 }; static_bounds<4, dynamic_range, 2> x{ 4 };
x.slice().slice(); x.slice().slice();
} }
@ -53,7 +56,7 @@ SUITE(bounds_test)
static_bounds<4, dynamic_range, 2> bounds{ 3 }; static_bounds<4, dynamic_range, 2> bounds{ 3 };
auto itr = bounds.begin(); auto itr = bounds.begin();
(void)itr;
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
span<int, 4, dynamic_range, 2> av(nullptr, bounds); span<int, 4, dynamic_range, 2> av(nullptr, bounds);
@ -70,13 +73,14 @@ SUITE(bounds_test)
{ {
static_bounds<7, 4, 2> b1; static_bounds<7, 4, 2> b1;
static_bounds<7, dynamic_range, 2> b2 = b1; static_bounds<7, dynamic_range, 2> b2 = b1;
(void)b2;
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
static_bounds<7, dynamic_range, 1> b4 = b2; static_bounds<7, dynamic_range, 1> b4 = b2;
#endif #endif
static_bounds<dynamic_range, dynamic_range, dynamic_range> b3 = b1; static_bounds<dynamic_range, dynamic_range, dynamic_range> b3 = b1;
static_bounds<7, 4, 2> b4 = b3; static_bounds<7, 4, 2> b4 = b3;
(void)b4;
static_bounds<dynamic_range> b11; static_bounds<dynamic_range> b11;

View File

@ -69,6 +69,7 @@ SUITE(NotNullTests)
MyDerived derived; MyDerived derived;
Unrelated unrelated; Unrelated unrelated;
not_null<Unrelated*> u = &unrelated; not_null<Unrelated*> u = &unrelated;
(void)u;
not_null<MyDerived*> p = &derived; not_null<MyDerived*> p = &derived;
not_null<MyBase*> q = &base; not_null<MyBase*> q = &base;
q = p; // allowed with heterogeneous copy ctor q = p; // allowed with heterogeneous copy ctor

View File

@ -27,7 +27,6 @@ using namespace gsl;
namespace namespace
{ {
void use(int&) {}
struct BaseClass {}; struct BaseClass {};
struct DerivedClass : BaseClass {}; struct DerivedClass : BaseClass {};
} }
@ -82,6 +81,7 @@ SUITE(span_tests)
span<BaseClass> avb = avd; span<BaseClass> avb = avd;
#endif #endif
span<const DerivedClass> avcd = avd; span<const DerivedClass> avcd = avd;
(void)avcd;
} }
TEST(boundary_checks) TEST(boundary_checks)
@ -198,6 +198,7 @@ SUITE(span_tests)
string str = "ttttttttttttttt"; // size = 15 string str = "ttttttttttttttt"; // size = 15
auto t = str.data(); auto t = str.data();
(void)t;
auto av3 = as_span(str); auto av3 = as_span(str);
overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't'); overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't');
} }
@ -213,9 +214,11 @@ SUITE(span_tests)
const std::array<double, 3> arr = {0.0, 0.0, 0.0}; const std::array<double, 3> arr = {0.0, 0.0, 0.0};
auto cv = as_span(arr); auto cv = as_span(arr);
(void)cv;
vector<float> vec(3); vector<float> vec(3);
auto dv = as_span(vec); auto dv = as_span(vec);
(void)dv;
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
auto dv2 = as_span(std::move(vec)); auto dv2 = as_span(std::move(vec));
@ -223,7 +226,7 @@ SUITE(span_tests)
} }
} }
template <class Bounds> void fn(const Bounds& b) { static_assert(Bounds::static_size == 60, "static bounds is wrong size"); } template <class Bounds> void fn(const Bounds&) { static_assert(Bounds::static_size == 60, "static bounds is wrong size"); }
TEST (span_reshape_test) TEST (span_reshape_test)
{ {
int a[3][4][5]; int a[3][4][5];
@ -261,6 +264,7 @@ SUITE(span_tests)
auto av = as_span(a); auto av = as_span(a);
auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2}); auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2});
auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1}); auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1});
(void)subsub;
} }
TEST(span_section) TEST(span_section)
@ -755,6 +759,7 @@ SUITE(span_tests)
CHECK_THROW(empty_av.cbegin()[0], fail_fast); CHECK_THROW(empty_av.cbegin()[0], fail_fast);
for (auto& v : empty_av) for (auto& v : empty_av)
{ {
(void)v;
CHECK(false); CHECK(false);
} }
} }
@ -767,6 +772,7 @@ SUITE(span_tests)
CHECK_THROW(empty_av.cbegin()[0], fail_fast); CHECK_THROW(empty_av.cbegin()[0], fail_fast);
for (auto& v : empty_av) for (auto& v : empty_av)
{ {
(void)v;
CHECK(false); CHECK(false);
} }
} }
@ -782,6 +788,7 @@ SUITE(span_tests)
for (auto& v : empty_sav) for (auto& v : empty_sav)
{ {
(void)v;
CHECK(false); CHECK(false);
} }
} }
@ -796,6 +803,7 @@ SUITE(span_tests)
for (auto& v : empty_sav) for (auto& v : empty_sav)
{ {
(void)v;
CHECK(false); CHECK(false);
} }
} }
@ -1412,7 +1420,7 @@ SUITE(span_tests)
CHECK_THROW(av1[10][3][4], fail_fast); CHECK_THROW(av1[10][3][4], fail_fast);
span<const double, dynamic_range, 6, 4> av2 = av1.as_span(dim<>(5), dim<6>(), dim<4>()); span<const double, dynamic_range, 6, 4> av2 = av1.as_span(dim<>(5), dim<6>(), dim<4>());
(void)av2;
} }
TEST(span_sub) TEST(span_sub)
@ -1554,9 +1562,11 @@ SUITE(span_tests)
// converting to dynamic_range a_v is always ok // converting to dynamic_range a_v is always ok
{ {
span<int, dynamic_range> av = av4; span<int, dynamic_range> av = av4;
(void)av;
} }
{ {
span<int, dynamic_range> av = arr; span<int, dynamic_range> av = arr;
(void)av;
} }
// initialization or assignment to static span that REDUCES size is NOT ok // initialization or assignment to static span that REDUCES size is NOT ok
@ -1572,6 +1582,7 @@ SUITE(span_tests)
{ {
span<int, dynamic_range> av = arr; span<int, dynamic_range> av = arr;
span<int, 2> av2 = av; span<int, 2> av2 = av;
(void)av2;
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
@ -1583,7 +1594,7 @@ SUITE(span_tests)
{ {
span<int, dynamic_range> av = arr; span<int, dynamic_range> av = arr;
auto f = [&]() {span<int, 2, 1> av2 = av.as_span(dim<>(2), dim<>(2));}; auto f = [&]() {span<int, 2, 1> av2 = av.as_span(dim<>(2), dim<>(2)); (void)av2; };
CHECK_THROW(f(), fail_fast); CHECK_THROW(f(), fail_fast);
} }
@ -1592,15 +1603,18 @@ SUITE(span_tests)
// you can convert statically // you can convert statically
{ {
span<int, 2> av2 = {arr, 2}; span<int, 2> av2 = {arr, 2};
(void)av2;
} }
{ {
span<int, 1> av2 = av4.first<1>(); span<int, 1> av2 = av4.first<1>();
(void)av2;
} }
// ...or dynamically // ...or dynamically
{ {
// NB: implicit conversion to span<int,2> from span<int,dynamic_range> // NB: implicit conversion to span<int,2> from span<int,dynamic_range>
span<int, 1> av2 = av4.first(1); span<int, 1> av2 = av4.first(1);
(void)av2;
} }
// initialization or assignment to static span that requires size INCREASE is not ok. // initialization or assignment to static span that requires size INCREASE is not ok.
@ -1616,13 +1630,13 @@ SUITE(span_tests)
} }
#endif #endif
{ {
auto f = [&]() {span<int, 4> av4 = {arr2, 2};}; auto f = [&]() {span<int, 4> av4 = {arr2, 2}; (void)av4; };
CHECK_THROW(f(), fail_fast); CHECK_THROW(f(), fail_fast);
} }
// this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one // this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one
span<int, dynamic_range> av = arr2; span<int, dynamic_range> av = arr2;
auto f = [&](){ span<int, 4> av2 = av; }; auto f = [&](){ span<int, 4> av2 = av; (void)av2; };
CHECK_THROW(f(), fail_fast); CHECK_THROW(f(), fail_fast);
} }

View File

@ -41,14 +41,14 @@ SUITE(string_span_tests)
{ {
std::string s = "Hello there world"; std::string s = "Hello there world";
cstring_span<> v = s; cstring_span<> v = s;
CHECK(v.length() == s.length()); CHECK(v.length() == static_cast<cstring_span<>::size_type>(s.length()));
} }
TEST(TestConstructFromStdVector) TEST(TestConstructFromStdVector)
{ {
std::vector<char> vec(5, 'h'); std::vector<char> vec(5, 'h');
string_span<> v = vec; string_span<> v = vec;
CHECK(v.length() == vec.size()); CHECK(v.length() == static_cast<string_span<>::size_type>(vec.size()));
} }
TEST(TestStackArrayConstruction) TEST(TestStackArrayConstruction)
@ -100,6 +100,7 @@ SUITE(string_span_tests)
{ {
char stack_string[] = "Hello"; char stack_string[] = "Hello";
cstring_span<> v = ensure_z(stack_string); cstring_span<> v = ensure_z(stack_string);
(void)v;
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
string_span<> v2 = v; string_span<> v2 = v;
string_span<> v3 = "Hello"; string_span<> v3 = "Hello";
@ -114,7 +115,7 @@ SUITE(string_span_tests)
char stack_string[] = "Hello"; char stack_string[] = "Hello";
cstring_span<> v = ensure_z(stack_string); cstring_span<> v = ensure_z(stack_string);
auto s2 = gsl::to_string(v); auto s2 = gsl::to_string(v);
CHECK(s2.length() == v.length()); CHECK(static_cast<cstring_span<>::size_type>(s2.length()) == v.length());
CHECK(s2.length() == 5); CHECK(s2.length() == 5);
} }
} }