Workaround gcc bug making it trigger an invalid warning

This commit is contained in:
Gael Guennebaud 2018-10-07 09:23:15 +02:00
parent c6a1ab4036
commit 409132bb81
2 changed files with 19 additions and 1 deletions

View File

@ -887,7 +887,15 @@ public:
pointer allocate(size_type num, const void* /*hint*/ = 0)
{
internal::check_size_for_overflow<T>(num);
return static_cast<pointer>( internal::aligned_malloc(num * sizeof(T)) );
size_type size = num * sizeof(T);
#if EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_AT_LEAST(7,0)
// workaround gcc bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
// It triggered eigen/Eigen/src/Core/util/Memory.h:189:12: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807
if(size>=std::size_t((std::numeric_limits<std::ptrdiff_t>::max)()))
return 0;
else
#endif
return static_cast<pointer>( internal::aligned_malloc(size) );
}
void deallocate(pointer p, size_type /*num*/)

View File

@ -117,6 +117,16 @@ void check_stdvector_quaternion(const QuaternionType&)
}
}
// the code below triggered an invalid warning with gcc >= 7
// eigen/Eigen/src/Core/util/Memory.h:189:12: warning: argument 1 value '18446744073709551612' exceeds maximum object size 9223372036854775807
// This has been reported to gcc there: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
void std_vector_gcc_warning()
{
typedef Eigen::Vector3f T;
std::vector<T, Eigen::aligned_allocator<T> > v;
v.push_back(T());
}
EIGEN_DECLARE_TEST(stdvector)
{
// some non vectorizable fixed sizes