Skip to content

Commit

Permalink
Merge pull request #380 from seoklab/clang-tools-19
Browse files Browse the repository at this point in the history
refactor: update more to clang tools v19
  • Loading branch information
jnooree authored Oct 18, 2024
2 parents 456f4d8 + db5fc7c commit 0a883f9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ InlayHints:
DeducedTypes: Yes
---
If:
PathMatch: "third_party/.*"
PathMatch: "third-party/.*"
Diagnostics:
Suppress: "*"
UnusedIncludes: None
14 changes: 5 additions & 9 deletions include/nuri/core/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ struct Isotope {
double abundance;
};

constexpr inline bool operator==(const Isotope &lhs,
const Isotope &rhs) noexcept {
constexpr bool operator==(const Isotope &lhs, const Isotope &rhs) noexcept {
return &lhs == &rhs;
}

constexpr inline bool operator!=(const Isotope &lhs,
const Isotope &rhs) noexcept {
constexpr bool operator!=(const Isotope &lhs, const Isotope &rhs) noexcept {
return &lhs != &rhs;
}

Expand Down Expand Up @@ -360,13 +358,11 @@ class Element {
std::vector<Isotope> isotopes_;
};

constexpr inline bool operator==(const Element &lhs,
const Element &rhs) noexcept {
constexpr bool operator==(const Element &lhs, const Element &rhs) noexcept {
return lhs.atomic_number() == rhs.atomic_number();
}

constexpr inline bool operator!=(const Element &lhs,
const Element &rhs) noexcept {
constexpr bool operator!=(const Element &lhs, const Element &rhs) noexcept {
return lhs.atomic_number() != rhs.atomic_number();
}

Expand Down Expand Up @@ -488,7 +484,7 @@ class PeriodicTable final {

// 118 elements + dummy
// NOLINTNEXTLINE(readability-identifier-naming)
constexpr inline static int kElementCount_ = 118 + 1;
constexpr static int kElementCount_ = 118 + 1;

private:
PeriodicTable() noexcept;
Expand Down
2 changes: 1 addition & 1 deletion include/nuri/core/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ namespace internal {
* @param atom An atom.
* @return Number of all neighbors of the atom, including implicit hydrogens.
*/
extern inline int all_neighbors(Molecule::Atom atom) {
inline int all_neighbors(Molecule::Atom atom) {
return atom.degree() + atom.data().implicit_hydrogens();
}

Expand Down
10 changes: 10 additions & 0 deletions include/nuri/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
#include <type_traits>
/// @endcond

#if defined(__clang_analyzer__) && __clang_major__ >= 18
#define NURI_CLANG_ANALYZER_NOLINT [[clang::suppress]]
#define NURI_CLANG_ANALYZER_NOLINT_BEGIN [[clang::suppress]] {
#define NURI_CLANG_ANALYZER_NOLINT_END }
#else
#define NURI_CLANG_ANALYZER_NOLINT
#define NURI_CLANG_ANALYZER_NOLINT_BEGIN
#define NURI_CLANG_ANALYZER_NOLINT_END
#endif

namespace nuri {
namespace internal {
// Use of std::underlying_type_t on non-enum types is UB until C++20.
Expand Down
35 changes: 12 additions & 23 deletions include/nuri/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
#include "nuri/eigen_config.h"
#include "nuri/meta.h"

// Introduced in clang 18
// #ifdef __clang_analyzer__
// #define NURI_CLANG_ANALYZER_NOLINT [[clang::suppress]]
// #define NURI_CLANG_ANALYZER_NOLINT_BEGIN [[clang::suppress]] {
// #define NURI_CLANG_ANALYZER_NOLINT_END }
// #else
// #define NURI_CLANG_ANALYZER_NOLINT
// #define NURI_CLANG_ANALYZER_NOLINT_BEGIN
// #define NURI_CLANG_ANALYZER_NOLINT_END
// #endif

namespace nuri {
template <class T, std::enable_if_t<std::is_trivially_copyable_v<T>, int> = 0>
constexpr T min(T a, T b) {
Expand Down Expand Up @@ -566,43 +555,43 @@ constexpr auto make_zipped_iterator(Iters... iters) {
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E operator|(E lhs, E rhs) {
constexpr E operator|(E lhs, E rhs) {
return static_cast<E>(static_cast<U>(lhs) | static_cast<U>(rhs));
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E &operator|=(E &self, E rhs) {
constexpr E &operator|=(E &self, E rhs) {
return self = self | rhs;
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E operator&(E lhs, E rhs) {
constexpr E operator&(E lhs, E rhs) {
return static_cast<E>(static_cast<U>(lhs) & static_cast<U>(rhs));
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E &operator&=(E &self, E rhs) {
constexpr E &operator&=(E &self, E rhs) {
return self = self & rhs;
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E operator^(E lhs, E rhs) {
constexpr E operator^(E lhs, E rhs) {
return static_cast<E>(static_cast<U>(lhs) ^ static_cast<U>(rhs));
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E &operator^=(E &self, E rhs) {
constexpr E &operator^=(E &self, E rhs) {
return self = self ^ rhs;
}

template <class E, class U = internal::underlying_type_t<E>, U = 0>
constexpr inline E operator~(E val) {
constexpr E operator~(E val) {
return static_cast<E>(~static_cast<U>(val));
}

template <class E, class U = internal::underlying_type_t<E>, U = 0,
std::enable_if_t<std::is_unsigned_v<U>, int> = 0>
constexpr inline E operator-(E val) {
constexpr E operator-(E val) {
return static_cast<E>(-static_cast<U>(val));
}

Expand Down Expand Up @@ -699,7 +688,7 @@ namespace internal {
set_name(props, std::string(name));
}

constexpr inline int negate_if_false(bool cond) {
constexpr int negate_if_false(bool cond) {
int ret = (static_cast<int>(cond) << 1) - 1;
ABSL_ASSUME(ret == 1 || ret == -1);
return ret;
Expand Down Expand Up @@ -854,8 +843,8 @@ inline std::string_view extension_no_dot(const std::filesystem::path &ext) {
return ext_view;
}

constexpr inline std::string_view slice(std::string_view str, std::size_t begin,
std::size_t end) {
constexpr std::string_view slice(std::string_view str, std::size_t begin,
std::size_t end) {
return str.substr(begin, end - begin);
}

Expand Down Expand Up @@ -915,7 +904,7 @@ inline Matrix3Xd stack(const std::vector<Vector3d> &vs) {
return m;
}

constexpr inline int value_if(bool cond, int val = 1) {
constexpr int value_if(bool cond, int val = 1) {
return static_cast<int>(cond) * val;
}

Expand Down
18 changes: 8 additions & 10 deletions src/fmt/sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "nuri/core/element.h"
#include "nuri/core/molecule.h"
#include "nuri/fmt/base.h"
#include "nuri/meta.h"
#include "nuri/utils.h"

namespace nuri {
Expand All @@ -67,10 +68,12 @@ namespace x3 = boost::spirit::x3;
using Iterator = std::vector<std::string>::const_iterator;

struct HeaderReadResult {
static HeaderReadResult failure() { return HeaderReadResult(); }
static HeaderReadResult failure() { return {}; }

static HeaderReadResult success(int version, int natoms, int nbonds) {
return HeaderReadResult(version, natoms, nbonds);
template <class N1, class N2, class N3>
static HeaderReadResult success(N1 version, N2 natoms, N3 nbonds) {
return { static_cast<int>(version), static_cast<int>(natoms),
static_cast<int>(nbonds) };
}

int version() const { return version_; }
Expand All @@ -83,11 +86,7 @@ struct HeaderReadResult {

private:
// Clang analyzer complains about uninitialized members
#ifdef __clang_analyzer__
HeaderReadResult(): version_(-1), natoms_(0), nbonds_(0) { }
#else
HeaderReadResult(): version_(-1) { }
#endif
NURI_CLANG_ANALYZER_NOLINT HeaderReadResult(): version_(-1) { }

HeaderReadResult(int v, int a, int b): version_(v), natoms_(a), nbonds_(b) { }

Expand Down Expand Up @@ -664,8 +663,7 @@ bool try_read_v3000_header(HeaderReadResult &metadata, Iterator &it,

ABSL_DCHECK(counts.size() >= 2);

metadata = HeaderReadResult::success(3000, static_cast<int>(counts[0]),
static_cast<int>(counts[1]));
metadata = HeaderReadResult::success(3000, counts[0], counts[1]);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions test/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ InheritParentConfig: true
ExtraArgsBefore:
- -Wno-gnu-zero-variadic-macro-arguments
- -Wno-unused-member-function
- -Wno-c++20-extensions
1 change: 1 addition & 0 deletions test/.clangd
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
CompileFlags:
Add:
- -Wno-gnu-zero-variadic-macro-arguments
- -Wno-c++20-extensions

0 comments on commit 0a883f9

Please sign in to comment.