Skip to content

Commit 6391644

Browse files
committed
Merge bitcoin#28737: doc: Fix bugprone-lambda-function-name errors
faa769d Fix bugprone-lambda-function-name errors (MarcoFalke) Pull request description: Inside a lambda, `__func__` will evaluate to something like `"operator()"`. Fix this by either removing it, or by using the real name. https://clang.llvm.org/extra/clang-tidy/checks/bugprone/lambda-function-name.html ACKs for top commit: TheCharlatan: ACK faa769d darosior: utACK faa769d Tree-SHA512: 0b562bd4ebd7f46ca3ebabeee67851ad30bd522fa57e5010e833b163664e51f5df645ff9ca35d22c3479fb27d9267d4e5d0d417d42729bf3ccf80d7944970e4e
2 parents ec5116a + faa769d commit 6391644

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Checks: '
33
bitcoin-*,
44
bugprone-argument-comment,
55
bugprone-use-after-move,
6+
bugprone-lambda-function-name,
67
misc-unused-using-decls,
78
modernize-use-default-member-init,
89
modernize-use-emplace,

src/rpc/mempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static RPCHelpMan getmempoolancestors()
465465
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
466466
}
467467

468-
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
468+
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
469469

470470
if (!fVerbose) {
471471
UniValue o(UniValue::VARR);

src/util/check.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class NonFatalCheckError : public std::runtime_error
2020
NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func);
2121
};
2222

23-
#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
24-
2523
/** Helper for CHECK_NONFATAL() */
2624
template <typename T>
2725
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
@@ -32,20 +30,6 @@ T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, co
3230
return std::forward<T>(val);
3331
}
3432

35-
/**
36-
* Identity function. Throw a NonFatalCheckError when the condition evaluates to false
37-
*
38-
* This should only be used
39-
* - where the condition is assumed to be true, not for error handling or validating user input
40-
* - where a failure to fulfill the condition is recoverable and does not abort the program
41-
*
42-
* For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace
43-
* asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC
44-
* caller, which can then report the issue to the developers.
45-
*/
46-
#define CHECK_NONFATAL(condition) \
47-
inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition)
48-
4933
#if defined(NDEBUG)
5034
#error "Cannot compile without assertions!"
5135
#endif
@@ -69,6 +53,25 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f
6953
return std::forward<T>(val);
7054
}
7155

56+
// All macros may use __func__ inside a lambda, so put them under nolint.
57+
// NOLINTBEGIN(bugprone-lambda-function-name)
58+
59+
#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
60+
61+
/**
62+
* Identity function. Throw a NonFatalCheckError when the condition evaluates to false
63+
*
64+
* This should only be used
65+
* - where the condition is assumed to be true, not for error handling or validating user input
66+
* - where a failure to fulfill the condition is recoverable and does not abort the program
67+
*
68+
* For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace
69+
* asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC
70+
* caller, which can then report the issue to the developers.
71+
*/
72+
#define CHECK_NONFATAL(condition) \
73+
inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition)
74+
7275
/** Identity function. Abort if the value compares equal to zero */
7376
#define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
7477

@@ -91,4 +94,6 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f
9194
throw NonFatalCheckError( \
9295
"Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__)
9396

97+
// NOLINTEND(bugprone-lambda-function-name)
98+
9499
#endif // BITCOIN_UTIL_CHECK_H

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,8 +5953,8 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
59535953
fs::path p_old,
59545954
fs::path p_new,
59555955
const fs::filesystem_error& err) {
5956-
LogPrintf("%s: error renaming file (%s): %s\n",
5957-
__func__, fs::PathToString(p_old), err.what());
5956+
LogPrintf("Error renaming path (%s) -> (%s): %s\n",
5957+
fs::PathToString(p_old), fs::PathToString(p_new), err.what());
59585958
GetNotifications().fatalError(strprintf(
59595959
"Rename of '%s' -> '%s' failed. "
59605960
"Cannot clean up the background chainstate leveldb directory.",

0 commit comments

Comments
 (0)