Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#28304: doc: Remove confusing assert linter
Browse files Browse the repository at this point in the history
fa6e6a3 doc: Remove confusing assert linter (MarcoFalke)

Pull request description:

  The `assert()` documentation and linter are redundant and confusing:

  * The source code already refuses to compile with `assert()` disabled.
  * They violate the assumptions about `Assert()`, which *requires* side effects.
  * The existing linter doesn't enforce the guideline, only checking for `++` and `--` side effects.

  Fix all issues by removing the docs and the linter. See also bitcoin/bitcoin#26684 (comment)

  Going forward everyone is free to use whatever code in this regard they think is the easiest to read. Also, everyone is still free to share style-nits, if they think it is a good use of their time and of the pull request author. Finally, the author is still free to dismiss or ignore this style-nit, or any other style-nit.

ACKs for top commit:
  hebasto:
    ACK fa6e6a3, I have reviewed the code and it looks OK.
  theStack:
    ACK fa6e6a3

Tree-SHA512: 686738d71e1316cc95e5d3f71869b55a02bfb137c795cc0875057f4410e564bc8eff03c985a2087b007fb08fc84551c7da1e8b30c7a9c3f2b14e5e44a5970236
  • Loading branch information
fanquake committed Oct 3, 2023
2 parents 8113ac0 + fa6e6a3 commit 4e78834
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
6 changes: 0 additions & 6 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,6 @@ Common misconceptions are clarified in those sections:
- Passing (non-)fundamental types in the [C++ Core
Guideline](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-conventional).

- Assertions should not have side-effects.

- *Rationale*: Even though the source code is set to refuse to compile
with assertions disabled, having side-effects in assertions is unexpected and
makes the code harder to understand.

- If you use the `.h`, you must link the `.cpp`.

- *Rationale*: Include files define the interface for the code in implementation files. Including one but
Expand Down
12 changes: 1 addition & 11 deletions test/lint/lint-assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,10 @@ def git_grep(params: [], error_msg: ""):


def main():
# PRE31-C (SEI CERT C Coding Standard):
# "Assertions should not contain assignments, increment, or decrement operators."
exit_code = git_grep([
"-E",
r"[^_]assert\(.*(\+\+|\-\-|[^=!<>]=[^=!<>]).*\);",
"--",
"*.cpp",
"*.h",
], "Assertions should not have side effects:")

# Aborting the whole process is undesirable for RPC code. So nonfatal
# checks should be used over assert. See: src/util/check.h
# src/rpc/server.cpp is excluded from this check since it's mostly meta-code.
exit_code |= git_grep([
exit_code = git_grep([
"-nE",
r"\<(A|a)ss(ume|ert) *\(.*\);",
"--",
Expand Down

0 comments on commit 4e78834

Please sign in to comment.