util/check: Add CHECK_NONFATAL identity function and NONFATAL_UNREACHABLE macro#24812
Conversation
70bff71 to
5eeb1e5
Compare
ebdd846 to
0661baf
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
0661baf to
3665422
Compare
vincenzopalazzo
left a comment
There was a problem hiding this comment.
LGTM, but I'm not a big fan of while(0) in C++, maybe C in yes
3665422 to
1e4d382
Compare
|
I've addressed the nits, thanks for your reviews. |
jonatack
left a comment
There was a problem hiding this comment.
ACK 1e4d38267feb69bab20ed06367d0a0adcd211068
Tested NONFATAL_UNREACHABLE
error code: -1
error message:
Internal bug detected: 'Unreachable code reached'
wallet/rpc/addresses.cpp:38 (operator())
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
Tested UNREACHABLE
Internal bug detected: 'Unreachable code reached'
wallet/rpc/addresses.cpp:38 (operator())
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
Aborted
If you retouch, it looks like #include <util/check.h> ought to be added to /rpc/blockchain.cpp and /rpc/util.cpp as well here.
f9cffe2 to
63b7534
Compare
|
re-ACK 63b753416abddb5f82ed32ff64a3372e65722fc2 |
|
Might be good to adjust the rpc linter as well for the new macros: #24856 Can be done in a follow-up to avoid a conflict for now. |
…E AND UNREACHABLE macros
63b7534 to
ee02c8b
Compare
|
ACK ee02c8b |
maflcko
left a comment
There was a problem hiding this comment.
Looks like this also fixes a warning with gcc-12.
ACK ee02c8b 🍨
Show signature
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK ee02c8bd9aedad8cfd3c2618035fe275da025fb9 🍨
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjsdwwArddL1iP4wywDs5YPWiBmm1hOzJSazUrpOb4gx4plkEEHXOXvGqIIwoRQ
IPnUtiwBnIfZ7UDTHRUCgY8jeLNmlfZAtKRqd8n9V7fat6Uarmubynkz66O4C/pH
lPV6WRkkcby+KDy01EJW10vGa0NqLg9VoxWiTIfb5LwoiyqcxnLYvJ6/Ir30GYsn
cgG9pOIRhyYPYJQp79Q2R1fZmNe1Vi53RfxCBBkNXJI+tlMeCT7N8A6IHh239Dak
KPQP43FDbgkhTuwDmf+RNipSqyvH0sWRTqNCei9Q6WWqwGiiRMH883GWtWO392bR
gvkf+TmQeVoWqELVi+fFk7d+14zLJnnIvouMESjacwCEbkL5j5OKSw8WW6g0Uffb
y5VyRSEFV02OrxMHmKFKn3UEAQm551gnILgu0ERvkKopedGXxttNdvsnj9nuYiMj
IyPjD7MVuu+Ri6IaFtJ7jxCUGm+cPgei79bOuumTrRt/6g/+QZZnniZyhNx5oVHz
CKvY4MQC
=l4Sj
-----END PGP SIGNATURE-----
| case Type::ANY: { | ||
| CHECK_NONFATAL(false); // Only for testing | ||
| NONFATAL_UNREACHABLE(); // Only for testing | ||
| } |
There was a problem hiding this comment.
This will also fix a warning on current master with gcc-12:
In file included from ./rpc/util.h:19,
from rpc/util.cpp:8:
rpc/util.cpp: In member function 'void RPCResult::ToSections(Sections&, OuterType, int) const':
./util/check.h:34:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
34 | if (!(condition)) { \
| ^~
rpc/util.cpp:796:9: note: in expansion of macro 'CHECK_NONFATAL'
796 | CHECK_NONFATAL(false); // Only for testing
| ^~~~~~~~~~~~~~
rpc/util.cpp:798:5: note: here
798 | case Type::NONE: {
| ^~~~
| template <typename T> | ||
| T&& inline_check_non_fatal(T&& val, const char* file, int line, const char* func, const char* assertion) | ||
| { | ||
| if (!(val)) { |
There was a problem hiding this comment.
| if (!(val)) { | |
| if (!val) { |
nit: No need for ().
| throw NonFatalCheckError( | ||
| format_internal_error(assertion, file, line, func, PACKAGE_BUGREPORT)); | ||
| } | ||
|
|
…CHABLE macro Summary: This is a backport of [[bitcoin/bitcoin#24812 | core#24812]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, sdulfari Reviewed By: #bitcoin_abc, sdulfari Subscribers: sdulfari Differential Revision: https://reviews.bitcoinabc.org/D13096
This PR replaces the macro
CHECK_NONFATALwith an identity function.I simplified the usage of
CHECK_NONFATALwhere applicable insrc/rpc.This function is useful in sanity checks for RPC and command-line interfaces.
Context: #24804 (comment).
Also adds
UNREACHABLE_NONFATALmacro.