Примеры ошибок, обнаруженных с помощью диагностики V1061
V1061. Extending 'std' or 'posix' namespace may result in undefined behavior.
DeepSpeech
V1061 Extending the 'std' namespace may result in undefined behavior. sized_iterator.hh 210
// Dirty hack because g++ 4.6 at least wants
// to do a bunch of copy operations.
namespace std {
inline void iter_swap(util::SizedIterator first,
util::SizedIterator second)
{
util::swap(*first, *second);
}
} // namespace std
RPCS3
V1061 Extending the 'std' namespace may result in undefined behavior. shared_ptr.hpp 1131
namespace std
{
template <typename T>
void swap(stx::single_ptr<T>& lhs, stx::single_ptr<T>& rhs) noexcept
{
lhs.swap(rhs);
}
template <typename T>
void swap(stx::shared_ptr<T>& lhs, stx::shared_ptr<T>& rhs) noexcept
{
lhs.swap(rhs);
}
}
CARLA
V1061 Extending the 'std' namespace may result in undefined behavior. Waypoint.cpp 11
// Waypoint.h
namespace std {
template <>
struct hash<carla::road::element::Waypoint> {
using argument_type = carla::road::element::Waypoint;
using result_type = uint64_t;
result_type operator()(const argument_type& waypoint) const;
};
} // namespace std
// Waypoint.cpp
namespace std {
using WaypointHash = hash<carla::road::element::Waypoint>; // <=
WaypointHash::result_type WaypointHash::operator()(
const argument_type &waypoint) const
{
WaypointHash::result_type seed = 0u;
boost::hash_combine(seed, waypoint.road_id);
boost::hash_combine(seed, waypoint.section_id);
boost::hash_combine(seed, waypoint.lane_id);
boost::hash_combine(seed,
static_cast<float>(std::floor(waypoint.s * 200.0)));
return seed;
}
} // namespace std
YTsaurus
V1061 Extending the 'std' namespace may result in undefined behavior. int128.h:378:1
template <bool IsSigned>
class TInteger128 { .... };
using ui128 = TInteger128<false>;
using i128 = TInteger128<true>;
// specialize std templates
namespace std
{
....
constexpr bool signbit(const ui128 arg) noexcept
{
Y_UNUSED(arg);
return false;
}
constexpr bool signbit(const i128 arg) noexcept
{
return GetHigh(arg) & 0x8000000000000000;
}
constexpr ui128 abs(const ui128 arg) noexcept
{
return arg;
}
constexpr i128 abs(const i128 arg) noexcept
{
return signbit(arg) ? (-arg) : arg;
}
}
YTsaurus
V1061 Extending the 'std' namespace may result in undefined behavior. compact_vector-inl.h:999:1
namespace std
{
/////////////////////////////////////////////////////////////////////
template <class T, size_t N>
void swap(NYT::TCompactVector<T, N>& lhs,
NYT::TCompactVector<T, N>& rhs)
{
lhs.swap(rhs);
}
/////////////////////////////////////////////////////////////////////
template <class T, size_t N>
struct hash<NYT::TCompactVector<T, N>>
{
size_t operator()(const NYT::TCompactVector<T, N>& container) const
{
size_t result = 0;
for (const auto& element : container)
{
NYT::HashCombine(result, element);
}
return result;
}
};
/////////////////////////////////////////////////////////////////////
}