refactor: Add LIFETIMEBOUND / -Wdangling-gsl to Assert() #25248

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2205-assert-lifetime-🐜 changing 2 files +8 −2
  1. maflcko commented at 2:29 PM on May 30, 2022: member

    Currently compiles clean, but I think it may still be useful.

    Can be tested by adding an &:

    diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
    index 5766fff92d..300c1ec60f 100644
    --- a/src/test/util_tests.cpp
    +++ b/src/test/util_tests.cpp
    @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(util_check)
     
         // Check -Wdangling-gsl does not trigger when copying the int. (It would
         // trigger on "const int&")
    -    const int nine{*Assert(std::optional<int>{9})};
    +    const int& nine{*Assert(std::optional<int>{9})};
         BOOST_CHECK_EQUAL(9, nine);
     }
     
    

    Output:

    test/util_tests.cpp:128:29: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling-gsl]
        const int& nine{*Assert(std::optional<int>{9})};
                                ^~~~~~~~~~~~~~~~~~~~~
    ./util/check.h:75:50: note: expanded from macro 'Assert'
    #define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
                                                     ^~~
    1 warning generated.
    
  2. jonatack commented at 2:33 PM on May 30, 2022: contributor

    Concept ACK

  3. DrahtBot added the label Refactoring on May 30, 2022
  4. DrahtBot added the label Utils/log/libs on May 30, 2022
  5. DrahtBot commented at 4:29 AM on May 31, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25112 (util: Move error message formatting of NonFatalCheckError to cpp by MarcoFalke)

    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.

  6. refactor: Add LIFETIMEBOUND / -Wdangling-gsl to Assert() fa3ea81c3e
  7. maflcko force-pushed on Aug 2, 2022
  8. jonatack commented at 1:16 PM on August 2, 2022: contributor

    ACK fa3ea81c3e7d962715788ab5525958a532c51414

    Cherry-picked this commit onto the Erlay branch I'm testing, rebased to master, Clang 15 debug build clean, then added the reference & to provoke the error.

      CXX      test/test_bitcoin-util_tests.o
    test/util_tests.cpp:128:29: error: object backing the pointer will be destroyed at the end of the full-expression [-Werror,-Wdangling-gsl]
        const int& nine{*Assert(std::optional<int>{9})};
                                ^~~~~~~~~~~~~~~~~~~~~
    ./util/check.h:75:50: note: expanded from macro 'Assert'
    #define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
                                                     ^~~
    1 error generated.
    

    Edit: not sure an ACK in a review comment is picked up by the script, so copied it over to the review dialog.

  9. achow101 commented at 7:25 PM on October 12, 2022: member
  10. fanquake requested review from theuni on Nov 1, 2022
  11. theuni approved
  12. theuni commented at 6:43 PM on November 2, 2022: member

    ACK fa3ea81c3e7d962715788ab5525958a532c51414

    I can't think of any reason not to :)

  13. fanquake referenced this in commit 2a7c9984db on Nov 3, 2022
  14. fanquake commented at 10:33 AM on November 3, 2022: member

    This has been merged.

  15. fanquake closed this on Nov 3, 2022

  16. maflcko deleted the branch on Nov 3, 2022
  17. sidhujag referenced this in commit c38fa5c44a on Nov 3, 2022
  18. Fabcien referenced this in commit 709d378e24 on Oct 16, 2023
  19. bitcoin locked this on Nov 3, 2023

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: 2026-04-13 15:13 UTC

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