Skip to content

Commit

Permalink
Enable clang-tidy cert-dcl58-cpp
Browse files Browse the repository at this point in the history
Re-enable this check and suppress the false-positives it was producing.

The issue regarding these false-positives can be found at
llvm/llvm-project#45454

Once that is fixed these suppressions can be removed.
  • Loading branch information
jbytheway committed May 21, 2023
1 parent 4704851 commit ecbceed
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 33 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ readability-*,\
-bugprone-throw-keyword-missing,\
-bugprone-unchecked-optional-access,\
-bugprone-unhandled-exception-at-new,\
-cert-dcl58-cpp,\
-cert-err33-c,\
-clang-analyzer-cplusplus.NewDeleteLeaks,\
-clang-analyzer-cplusplus.StringChecker,\
Expand Down
8 changes: 2 additions & 6 deletions src/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,15 @@ inline auto project_bounds( const coord_point<tripoint, Origin, CoarseScale> &co

} // namespace coords

namespace std
{

template<typename Point, coords::origin Origin, coords::scale Scale>
struct hash<coords::coord_point<Point, Origin, Scale>> {
// NOLINTNEXTLINE(cert-dcl58-cpp)
struct std::hash<coords::coord_point<Point, Origin, Scale>> {
std::size_t operator()( const coords::coord_point<Point, Origin, Scale> &p ) const {
const hash<Point> h{};
return h( p.raw() );
}
};

} // namespace std

/** Typedefs for point types with coordinate mnemonics.
*
* Each name is of the form (tri)point_<origin>_<scale> where <origin> tells you the
Expand Down
6 changes: 2 additions & 4 deletions src/int_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ class int_id
};

// Support hashing of int based ids by forwarding the hash of the int.
namespace std
{
template<typename T>
struct hash< int_id<T> > {
// NOLINTNEXTLINE(cert-dcl58-cpp)
struct std::hash<int_id<T>> {
std::size_t operator()( const int_id<T> &v ) const noexcept {
return hash<int>()( v.to_i() );
}
};
} // namespace std

#endif // CATA_SRC_INT_ID_H
8 changes: 1 addition & 7 deletions src/mapgendata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ void mapgen_arguments::deserialize( const JsonValue &ji )
ji.read( map, true );
}

// NOLINTNEXTLINE(cert-dcl58-cpp)
namespace std
{

size_t hash<mapgen_arguments>::operator()( const mapgen_arguments &args ) const noexcept
size_t std::hash<mapgen_arguments>::operator()( const mapgen_arguments &args ) const noexcept
{
cata::range_hash h;
return h( args.map );
}

} // namespace std

static const regional_settings dummy_regional_settings;

mapgendata::mapgendata( map &mp, dummy_settings_t )
Expand Down
8 changes: 3 additions & 5 deletions src/overmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,14 @@ extern template struct pos_dir<tripoint_rel_omt>;
using om_pos_dir = pos_dir<tripoint_om_omt>;
using rel_pos_dir = pos_dir<tripoint_rel_omt>;

namespace std
{
template<typename Tripoint>
struct hash<pos_dir<Tripoint>> {
size_t operator()( const pos_dir<Tripoint> &p ) const {
// NOLINTNEXTLINE(cert-dcl58-cpp)
struct std::hash<pos_dir<Tripoint>> {
std::size_t operator()( const pos_dir<Tripoint> &p ) const {
cata::tuple_hash h;
return h( std::make_tuple( p.p, p.dir ) );
}
};
} // namespace std

class overmap
{
Expand Down
10 changes: 4 additions & 6 deletions src/string_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class string_identity_static
friend class string_id;

template<typename T>
friend struct std::hash;
friend struct std::hash; // NOLINT(cert-dcl58-cpp)
};

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ class string_identity_dynamic
friend class string_id;

template<typename T>
friend struct std::hash;
friend struct std::hash; // NOLINT(cert-dcl58-cpp)
};

template<typename T>
Expand Down Expand Up @@ -362,16 +362,14 @@ class string_id
};

// Support hashing of string based ids by forwarding the hash of the string.
namespace std
{
template<typename T>
struct hash<string_id<T>> {
// NOLINTNEXTLINE(cert-dcl58-cpp)
struct std::hash<string_id<T>> {
std::size_t operator()( const string_id<T> &v ) const noexcept {
using IdType = decltype( v._id._id );
return std::hash<IdType>()( v._id._id );
}
};
} // namespace std

/** Lexicographic order comparator for string_ids */
template<typename T>
Expand Down
7 changes: 3 additions & 4 deletions src/vpart_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class vehicle_part_iterator
}
};

namespace std
{
template<class T> struct iterator_traits<vehicle_part_iterator<T>> {
template<class T>
// NOLINTNEXTLINE(cert-dcl58-cpp)
struct std::iterator_traits<vehicle_part_iterator<T>> {
using difference_type = size_t;
using value_type = vpart_reference;
// TODO: maybe change into random access iterator? This requires adding
Expand All @@ -90,7 +90,6 @@ template<class T> struct iterator_traits<vehicle_part_iterator<T>> {
using pointer = const vpart_reference *;
using iterator_category = std::forward_iterator_tag;
};
} // namespace std

/**
* The generic range, it misses the `bool contained(size_t)` function that is
Expand Down

0 comments on commit ecbceed

Please sign in to comment.