Skip to content

Fix clang++'s warning about self-assign #2245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util/sharing_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Author: Daniel Poetzl
#define SN_ASSERT_USE(v, b) SN_ASSERT(b)

Choose a reason for hiding this comment

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

If the intention is to always mark v as used, it should also be done here.

#else
#define SN_ASSERT(b)
#define SN_ASSERT_USE(v, b) v = v;
#define SN_ASSERT_USE(v, b) static_cast<void>(v);

Choose a reason for hiding this comment

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

Casting to void is not as portable as I thought (it's not going to shut up all compilers), in here H. Sutter suggests something like

template<typename T>
void mark_as_used(const T&) {}

Although I suppose as long as it works for the compilers we're actually using I guess it's good enough.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the full fix is to refactor the code so that this macro isn't necessary at all. There is a single use case at the moment, and a somewhat-dummy workaround would be adding a return value to the function.

#endif

// clang-format off
Expand Down