mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Cleanup additional GCC warnings
When turning on the following flags, several additional warnings were generated, which have been cleaned up in this patch. The flags included: -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wctor-dtor-privacy -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Woverloaded-virtual
This commit is contained in:
parent
38f453d608
commit
d641796b21
@ -1451,7 +1451,7 @@ public:
|
|||||||
constexpr size_type length() const noexcept { return this->size(); }
|
constexpr size_type length() const noexcept { return this->size(); }
|
||||||
|
|
||||||
// length of the multi_span in bytes
|
// length of the multi_span in bytes
|
||||||
constexpr size_type size_bytes() const noexcept { return sizeof(value_type) * this->size(); }
|
constexpr size_type size_bytes() const noexcept { return narrow_cast<size_type>(sizeof(value_type)) * this->size(); }
|
||||||
|
|
||||||
// length of the multi_span in bytes
|
// length of the multi_span in bytes
|
||||||
constexpr size_type length_bytes() const noexcept { return this->size_bytes(); }
|
constexpr size_type length_bytes() const noexcept { return this->size_bytes(); }
|
||||||
@ -1653,7 +1653,8 @@ constexpr auto as_multi_span(multi_span<const byte, Dimensions...> s) noexcept -
|
|||||||
ConstByteSpan::bounds_type::static_size % narrow_cast<std::ptrdiff_t>(sizeof(U)) == 0),
|
ConstByteSpan::bounds_type::static_size % narrow_cast<std::ptrdiff_t>(sizeof(U)) == 0),
|
||||||
"Target type must be a trivial type and its size must match the byte array size");
|
"Target type must be a trivial type and its size must match the byte array size");
|
||||||
|
|
||||||
Expects((s.size_bytes() % sizeof(U)) == 0 && (s.size_bytes() / sizeof(U)) < PTRDIFF_MAX);
|
Expects((s.size_bytes() % narrow_cast<std::ptrdiff_t>(sizeof(U))) == 0 &&
|
||||||
|
(s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))) < PTRDIFF_MAX);
|
||||||
return {reinterpret_cast<const U*>(s.data()),
|
return {reinterpret_cast<const U*>(s.data()),
|
||||||
s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))};
|
s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))};
|
||||||
}
|
}
|
||||||
|
2
gsl/span
2
gsl/span
@ -494,7 +494,7 @@ public:
|
|||||||
constexpr index_type length() const noexcept { return size(); }
|
constexpr index_type length() const noexcept { return size(); }
|
||||||
constexpr index_type size() const noexcept { return storage_.size(); }
|
constexpr index_type size() const noexcept { return storage_.size(); }
|
||||||
constexpr index_type length_bytes() const noexcept { return size_bytes(); }
|
constexpr index_type length_bytes() const noexcept { return size_bytes(); }
|
||||||
constexpr index_type size_bytes() const noexcept { return size() * sizeof(element_type); }
|
constexpr index_type size_bytes() const noexcept { return size() * narrow_cast<index_type>(sizeof(element_type)); }
|
||||||
constexpr bool empty() const noexcept { return size() == 0; }
|
constexpr bool empty() const noexcept { return size() == 0; }
|
||||||
|
|
||||||
// [span.elem], span element access
|
// [span.elem], span element access
|
||||||
|
@ -331,7 +331,7 @@ public:
|
|||||||
// Container signature should work for basic_string after C++17 version exists
|
// Container signature should work for basic_string after C++17 version exists
|
||||||
template <class Traits, class Allocator>
|
template <class Traits, class Allocator>
|
||||||
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator>& str)
|
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator>& str)
|
||||||
: span_(&str[0], str.length())
|
: span_(&str[0], narrow_cast<std::ptrdiff_t>(str.length()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ else()
|
|||||||
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||||
if(COMPILER_SUPPORTS_CXX14)
|
if(COMPILER_SUPPORTS_CXX14)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++14 -O3 -Wall -Wno-missing-braces")
|
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")
|
||||||
elseif(COMPILER_SUPPORTS_CXX11)
|
elseif(COMPILER_SUPPORTS_CXX11)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -std=c++11 -O3 -Wall -Wno-missing-braces")
|
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")
|
||||||
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()
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gsl;;
|
using namespace gsl;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ SUITE(bounds_test)
|
|||||||
j++)
|
j++)
|
||||||
{
|
{
|
||||||
use(j);
|
use(j);
|
||||||
use(point[j]);
|
use(point[static_cast<size_t>(j)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1427,14 +1427,14 @@ SUITE(multi_span_tests)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t check_sum = 0;
|
auto check_sum = 0;
|
||||||
for (auto i = 0; i < length; ++i) {
|
for (auto i = 0; i < length; ++i) {
|
||||||
check_sum += av[i][1];
|
check_sum += av[i][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto idx = 0;
|
auto idx = 0;
|
||||||
size_t sum = 0;
|
auto sum = 0;
|
||||||
for (auto num : section) {
|
for (auto num : section) {
|
||||||
CHECK(num == av[idx][1]);
|
CHECK(num == av[idx][1]);
|
||||||
sum += num;
|
sum += num;
|
||||||
@ -1444,8 +1444,8 @@ SUITE(multi_span_tests)
|
|||||||
CHECK(sum == check_sum);
|
CHECK(sum == check_sum);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
size_t idx = length - 1;
|
auto idx = length - 1;
|
||||||
size_t sum = 0;
|
auto sum = 0;
|
||||||
for (auto iter = section.rbegin(); iter != section.rend(); ++iter) {
|
for (auto iter = section.rbegin(); iter != section.rend(); ++iter) {
|
||||||
CHECK(*iter == av[idx][1]);
|
CHECK(*iter == av[idx][1]);
|
||||||
sum += *iter;
|
sum += *iter;
|
||||||
@ -1650,7 +1650,7 @@ SUITE(multi_span_tests)
|
|||||||
{
|
{
|
||||||
multi_span<int, dynamic_range> av = a;
|
multi_span<int, dynamic_range> av = a;
|
||||||
auto wav = as_writeable_bytes(av);
|
auto wav = as_writeable_bytes(av);
|
||||||
CHECK(wav.data() == (byte*) &a[0]);
|
CHECK(wav.data() == reinterpret_cast<byte*>(&a[0]));
|
||||||
CHECK(wav.length() == sizeof(a));
|
CHECK(wav.length() == sizeof(a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ SUITE(NotNullTests)
|
|||||||
not_null<Unrelated*> s = reinterpret_cast<Unrelated*>(p);
|
not_null<Unrelated*> s = reinterpret_cast<Unrelated*>(p);
|
||||||
#endif
|
#endif
|
||||||
not_null<Unrelated*> t = reinterpret_cast<Unrelated*>(p.get());
|
not_null<Unrelated*> t = reinterpret_cast<Unrelated*>(p.get());
|
||||||
CHECK((void*)p.get() == (void*)t.get());
|
CHECK(reinterpret_cast<void*>(p.get()) == reinterpret_cast<void*>(t.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestNotNullAssignment)
|
TEST(TestNotNullAssignment)
|
||||||
|
@ -1336,8 +1336,8 @@ SUITE(span_tests)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
auto f = [&]() {
|
auto f = [&]() {
|
||||||
span<int, 4> s4 = {arr2, 2};
|
span<int, 4> _s4 = {arr2, 2};
|
||||||
static_cast<void>(s4);
|
static_cast<void>(_s4);
|
||||||
};
|
};
|
||||||
CHECK_THROW(f(), fail_fast);
|
CHECK_THROW(f(), fail_fast);
|
||||||
}
|
}
|
||||||
@ -1345,8 +1345,8 @@ SUITE(span_tests)
|
|||||||
// this should fail - we are trying to assign a small dynamic span to a fixed_size larger one
|
// this should fail - we are trying to assign a small dynamic span to a fixed_size larger one
|
||||||
span<int> av = arr2;
|
span<int> av = arr2;
|
||||||
auto f = [&]() {
|
auto f = [&]() {
|
||||||
span<int, 4> s4 = av;
|
span<int, 4> _s4 = av;
|
||||||
static_cast<void>(s4);
|
static_cast<void>(_s4);
|
||||||
};
|
};
|
||||||
CHECK_THROW(f(), fail_fast);
|
CHECK_THROW(f(), fail_fast);
|
||||||
}
|
}
|
||||||
|
@ -701,7 +701,7 @@ SUITE(strided_span_tests)
|
|||||||
|
|
||||||
int s = sizeof(int) / sizeof(byte);
|
int s = sizeof(int) / sizeof(byte);
|
||||||
auto d2 = 3 * s;
|
auto d2 = 3 * s;
|
||||||
auto d1 = sizeof(int) * 12 / d2;
|
auto d1 = narrow_cast<int>(sizeof(int)) * 12 / d2;
|
||||||
|
|
||||||
// convert to 4x12 array of bytes
|
// convert to 4x12 array of bytes
|
||||||
auto av = as_multi_span(as_bytes(as_multi_span(arr, 4)), dim(d1), dim(d2));
|
auto av = as_multi_span(as_bytes(as_multi_span(arr, 4)), dim(d1), dim(d2));
|
||||||
|
@ -67,7 +67,7 @@ SUITE(utils_tests)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
void g() { j += 1; };
|
void g() { j += 1; }
|
||||||
TEST(finally_function_ptr)
|
TEST(finally_function_ptr)
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user