util: Make Assume() usable as unary expression #21317

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2102-utilAssumeUnary changing 2 files +4 −1
  1. MarcoFalke commented at 3:31 pm on February 28, 2021: member
    Assume shouldn’t behave different at the call site depending on build flags. Currently compilation fails if it is used as expression. Fix that by using the lambda approach from Assert() without the assert().
  2. MarcoFalke commented at 3:32 pm on February 28, 2021: member
    Reported here: #21236 (review)
  3. practicalswift commented at 3:45 pm on February 28, 2021: contributor
    Concept ACK
  4. DrahtBot added the label Utils/log/libs on Feb 28, 2021
  5. jnewbery commented at 10:43 am on March 4, 2021: member
    Concept ACK
  6. MarcoFalke force-pushed on Mar 4, 2021
  7. util: Make Assume() usable as unary expression fa4cebadcf
  8. MarcoFalke force-pushed on Mar 4, 2021
  9. in src/test/util_tests.cpp:81 in fa4cebadcf
    75@@ -76,6 +76,9 @@ BOOST_AUTO_TEST_CASE(util_check)
    76     const int two = *Assert(p_two);
    77     Assert(two == 2);
    78     Assert(true);
    79+    // Check that Assume can be used as unary expression
    80+    const bool result{Assume(two == 2)};
    81+    Assert(result);
    


    MarcoFalke commented at 11:08 am on March 4, 2021:
    fun fact: I tried to minimize the test by writing Assert(Assume(two == 2)), but that only works in C++20.

    hebasto commented at 2:24 pm on October 31, 2021:

    The added lines are intended to test Assume, therefore we could s/Assert(result);/BOOST_CHECK(true);/ to suppress “Test case util_tests/util_check did not check any assertions” in

     0$ ./src/test/test_bitcoin -t util_tests/util_check -l test_suite
     1Running 1 test case...
     2Entering test module "Bitcoin Core Test Suite"
     3test/util_tests.cpp(48): Entering test suite "util_tests"
     4test/util_tests.cpp(75): Entering test case "util_check"
     5Test case util_tests/util_check did not check any assertions
     6test/util_tests.cpp(75): Leaving test case "util_check"; testing time: 9563us
     7test/util_tests.cpp(48): Leaving test suite "util_tests"; testing time: 9634us
     8Leaving test module "Bitcoin Core Test Suite"; testing time: 9695us
     9
    10*** No errors detected
    

    If Assert(result); is really required (but I cannot see reasons), maybe add BOOST_CHECK(true); as it is done here: https://github.com/bitcoin/bitcoin/blob/7efc628539573af4b4a76d93b853cc46e9e52eae/src/test/util_tests.cpp#L102 ?


    MarcoFalke commented at 2:31 pm on October 31, 2021:
    BOOST_CHECK(result); should also work

    hebasto commented at 2:46 pm on October 31, 2021:
    Right. I meant it :) My copy-paste error…
  10. jnewbery commented at 10:20 am on March 17, 2021: member
    ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887
  11. practicalswift commented at 7:20 pm on March 17, 2021: contributor
    cr ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887: patch looks correct and commit hash starts with fa
  12. MarcoFalke merged this on Mar 22, 2021
  13. MarcoFalke closed this on Mar 22, 2021

  14. MarcoFalke deleted the branch on Mar 22, 2021
  15. sidhujag referenced this in commit a2d9d9ae65 on Mar 22, 2021
  16. Fabcien referenced this in commit 594794938f on Jan 21, 2022
  17. PastaPastaPasta referenced this in commit e235a5873f on Jun 19, 2022
  18. PastaPastaPasta referenced this in commit 9101e82bf2 on Jun 19, 2022
  19. PastaPastaPasta referenced this in commit 10979f1a74 on Jun 27, 2022
  20. DrahtBot locked this on Oct 31, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me