Skip to content

Conversation

@1uc
Copy link
Contributor

@1uc 1uc commented Jun 14, 2025

Apply clang-tidy fixes for google-explicit-constructor. This prevents implicit conversion and allows passing initializer list to function, to create a temporary argument from the initializer list.

using Object::Object; // bring DataSet(hid_t)

DataSet(Object&& o) noexcept
explicit DataSet(Object&& o) noexcept
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because we definitely don't want to silently convert any Object to DataSet.

/// \brief Create a variable length string HDF5 datatype.
///
VariableLengthStringType(CharacterSet character_set = CharacterSet::Ascii);
explicit VariableLengthStringType(CharacterSet character_set = CharacterSet::Ascii);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because conversion seems unexpected.

/// \brief Initializes a compound type from a DataType
/// \param type
inline CompoundType(DataType&& type)
inline explicit CompoundType(DataType&& type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because not every DataType is a CompoundType. Hence, no conversion.

@codecov
Copy link

codecov bot commented Jun 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

}

Group(Object&& o) noexcept
explicit Group(Object&& o) noexcept
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because silently converting any Object to Group is unexpected.

class SilenceHDF5 {
public:
inline SilenceHDF5(bool enable = true)
inline explicit SilenceHDF5(bool enable = true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because bool isn't related to the concept of silencing HDF5 error output.


struct HighFiveIterateData {
inline HighFiveIterateData(std::vector<std::string>& my_names)
explicit HighFiveIterateData(std::vector<std::string>& my_names)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because internal.

/// \param list List of continuous coordinates (e.g.: in 2 dimensions space
/// `ElementSet{1, 2, 3 ,4}` creates points `(1, 2)` and `(3, 4)`).
explicit ElementSet(std::initializer_list<std::size_t> list);
ElementSet(std::initializer_list<std::size_t> list);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably OK, because more permissive, meaning it shouldn't break anything and:

void foo(ElementSet);
foo({1, 2, 3});

seems fair.

const std::vector<size_t>& count_ = {},
const std::vector<size_t>& stride_ = {},
const std::vector<size_t>& block_ = {})
explicit RegularHyperSlab(const std::vector<size_t>& offset_,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because an std::vector<size_t> isn't tightly related to RegularHyperSlab.

class HyperCube {
public:
HyperCube(size_t rank)
explicit HyperCube(size_t rank)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because internal.

///
/// \param list List of N-dim points.
explicit ElementSet(std::initializer_list<std::vector<std::size_t>> list);
ElementSet(std::initializer_list<std::vector<std::size_t>> list);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably OK, see above.

class Exception: public std::exception {
public:
Exception(const std::string& err_msg)
explicit Exception(const std::string& err_msg)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undecided: std::runtime_error allows conversion from std::string (and char*).

/// \param t_members
/// \param size
inline CompoundType(const std::vector<member_def>& t_members, size_t size = 0)
inline explicit CompoundType(const std::vector<member_def>& t_members, size_t size = 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undecided: member_def is tightly linked to CompoundType. Hence, maybe not worth breaking user code over something that's unlikely to be very surprising.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert, not worth breaking anyone's code over this.

EnumType(const EnumType& other) = default;

EnumType(const std::vector<member_def>& t_members)
explicit EnumType(const std::vector<member_def>& t_members)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undecided: member_def is tightly linked to EnumType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert, same argument.

@1uc 1uc marked this pull request as ready for review June 14, 2025 13:38
@1uc 1uc mentioned this pull request Jun 14, 2025
@1uc 1uc force-pushed the 1uc/explicit-ctors branch 2 times, most recently from 8ae74e5 to 0bd4945 Compare June 20, 2025 07:00
This commit follows applies the google-explicit-constructor rules as the
default:

  * all ctors are explicit,
  * except ctors using the initializer list, those are never
    explicit.

Exceptions are made for cases where conversion has little risk of being
bugprone, e.g. because the type of the argument of the ctor is closely
linked to the object being constructed.
@1uc 1uc force-pushed the 1uc/explicit-ctors branch from 0bd4945 to e7dd0ff Compare June 20, 2025 07:01
@1uc 1uc merged commit 1dc8406 into main Jun 20, 2025
35 checks passed
@1uc 1uc deleted the 1uc/explicit-ctors branch June 20, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants