-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add UNREACHABLE
macro
#26504
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
Add UNREACHABLE
macro
#26504
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Concept ACK |
~0 - agree with the earlier discussion in #24812. Why do we need to redefine This will be another thing developers have to look up, rather than seeing If we were going to introduce an unreachable macro, we could at least use |
They are not broken, as they do not violate the C++ standard. Of course, the way how they consider warnings for
For non-Windows targets warnings are inconsistent between GCC and Clang as well (remove
That could be like an implementation of But the suggested macro is safer when it comes to handle, for example, non-defined-explicitly enumeration values, as |
Updated 05ffaf4 -> 39d681e (pr26504.01 -> pr26504.02):
|
@@ -695,7 +696,7 @@ uint32_t CNetAddr::GetLinkedIPv4() const | |||
// Teredo tunneled IPv4: the IPv4 address is in the last 4 bytes of the address, but bitflipped | |||
return ~ReadBE32(Span{m_addr}.last(ADDR_IPV4_SIZE).data()); | |||
} | |||
assert(false); | |||
UNREACHABLE(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now also changing code that does not use switch statements, and I assume doesn't warn under mingw-w64, becoming inconsistent with the rest of the codebase. If we are going to change some of these, we should be changing all, otherwise this is just random refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume doesn't warn under mingw-w64
It does when compiling with -O0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There'd be test/lint/lint-assertions.py if this is a goal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be changing all, otherwise this is just random refactoring.
In that case, what macro name could be appropriate?
Updated 39d681e -> dd47e2a (pr26504.02 -> pr26504.03):
|
src/util/check.cpp
Outdated
|
||
void unreachable_fail(const char* file, int line, const char* func) | ||
{ | ||
std::cerr << strprintf("Internal bug detected: Unreachable code reached (fatal, aborting)\n%s:%d (%s)\nPlease report this issue here: %s\n", file, line, func, PACKAGE_BUGREPORT) << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could rebase and use the existing string template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Updated dd47e2a -> 426d6be (pr26504.03 -> pr26504.04):
To make this PR compatible with the recently merged #26645, the |
Rebased on top of the #26688 and drafted until the latter is being reviewed. |
Concept ACK on First push is |
Co-authored-by: Aurèle Oulès <aurele@oules.com> Co-authored-by: MacroFake <falke.marco@gmail.com>
@hebasto Let us know if you'll pick this up again or if you want someone else to do it? |
Almost ready :) |
Done. Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Review lgtm
Looks like you forgot to include the doc change? abacaef#diff-5e319039d67254bed6ca82562ec5f560f102004aa4806e4ca77f5d0065c65fbb Also, could update title, description and commit message? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is done, IIUC the developer notes should be updated.
@@ -12,6 +12,7 @@ | |||
#include <logging.h> | |||
#include <tinyformat.h> | |||
#include <util/chaintype.h> | |||
#include <util/check.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potential downside with this change is the util/check.h
code is added to a fair number of compilation units (unless the header was already missing). Also, it looks like some cases haven't been updated. Maybe only use it for new or touched code going forward?
This change prevents `-Wreturn-type` and `C4715` warnings when building for/on Windows.
UNREACHABLE
macro and drop -Wreturn-type
/C4715
warnings suppressionsUNREACHABLE
macro
The title an the description have been updated. What update for commit messages would you like to see? |
Either it does or it doesn't? If it does, then any workarounds should be removed, and warnings re-enabled. If it doesn't, there's no point to this refactoring at all, if it doesn't even acheive the stated goals.
Which CI is this? The only one where it is an issue has the warnings disabled? |
I don't use g++, nor Windows, locally, so this is a general problem of not knowing which function is marked noreturn by g++ or msvc internally. Having a macro that is known to work on all compilers is helpful, I think. I don't care about updating the existing code, but I think having a macro for those that find it helpful, can't hurt, can it? |
I agree that having a macro could be useful. Separately, note that upstream, the missing |
To be clear, I agree, and am still a NACK to any code changes here. |
The
UNREACHABLE
macro was suggested in #24812, but during reviewing it has been dropped:This macro prevents compiler warnings --
-Wreturn-type
(GCC) andC4715
(MSVC) -- when building for/on Windows.