Remove ‘boost::optional’-related false positive -Wmaybe-uninitialized warnings on GCC compiler #15292

pull hebasto wants to merge 1 commits into bitcoin:master from hebasto:20190130-gcc-maybeuninitialized changing 3 files +13 −2
  1. hebasto commented at 11:39 am on January 30, 2019: member

    #14711 introduced some warnings when building with gcc compiler.

    See:

    This gcc issue has been known since version 4.6.0 and last updated in 2017. From the boost docs:

    The default constructor of optional creates an uninitialized optional object.

    Also: False positive with -Wmaybe-uninitialized (pointed out by @Empact)

    This PR removes these warnings.

    cc: @Empact @practicalswift

  2. fanquake added the label Wallet on Jan 30, 2019
  3. fanquake added the label Refactoring on Jan 30, 2019
  4. hebasto force-pushed on Jan 30, 2019
  5. DrahtBot commented at 12:14 pm on January 30, 2019: member

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

    Conflicts

    No conflicts as of last run.

  6. MarcoFalke commented at 1:41 pm on January 30, 2019: member
    Generally we don’t work around bugs in a compiler if they are only warning related and fixed in recent versions.
  7. hebasto commented at 1:44 pm on January 30, 2019: member

    @MarcoFalke

    Generally we don’t work around bugs in a compiler if they are only warning related and fixed in recent versions.

    Which recent version of gcc do you mean?

  8. MarcoFalke commented at 2:41 pm on January 30, 2019: member
    According to the bug report, it was fixed in gcc6. I am using clang7.
  9. ryanofsky commented at 3:29 pm on January 30, 2019: member

    I would prefer not to make these changes since I think they make the code less readable, are only applicable to older buggy versions of gcc, and just avoid warnings not errors.

    But I will add my utACK 595b62fcf93aedc852dc93a7b5f112f11e50a5ef since the changes do look safe, and other people might want them.

    I wonder what would happen if you tried to replace:

    0Optional<int> height;
    

    with:

    0Optional<int> height = nullopt;
    

    I think a change like that would be more readable.

  10. hebasto commented at 5:09 pm on January 30, 2019: member

    @MarcoFalke

    According to the bug report, it was fixed in gcc6. I am using clang7.

    I am using gcc 7.3.0 (both Linux Mint 19.1 and Ubuntu Bionic). Warnings are still present. @ryanofsky

    Optional<int> height = nullopt;

    I’ve tried this approach while working on this PR. nullopt did not help. Perhaps this is due to the lazy initialization inside boost::optional.

  11. MarcoFalke commented at 5:13 pm on January 30, 2019: member
    gcc8 will also spit out a false positive warning, since it can not infer that either none or both of altheight and height are initialized. Not sure if this should be fixed or how.
  12. Empact commented at 6:51 pm on January 30, 2019: member

    I think “The default constructor of optional creates an uninitialized optional object.” may be misleading as default-constructed values are valid, e.g.. boost::optional has an is_initialized member that is false on default initialization, and just means the object is falsey.

    Other thoughts: I would prefer not to use auto here given there are plenty of numeric types. I would access this functionality via src/optional.h, where the other boost::optional references are.

    Incidentally here’s the doc where boost recommends this fix. No opinion on whether this should be fixed.

  13. hebasto commented at 6:57 pm on January 30, 2019: member
    @Empact TIL. Thank you.
  14. hebasto force-pushed on Jan 30, 2019
  15. hebasto commented at 7:12 pm on January 30, 2019: member
    @Empact your comment has been addressed.
  16. hebasto renamed this:
    Remove 'boost::optional'-related gcc warnings
    Remove 'boost::optional'-related false positive -Wmaybe-uninitialized warnings on GCC compiler
    on Jan 30, 2019
  17. laanwj commented at 7:31 pm on January 30, 2019: member

    I’m using gcc 7.3.0 on my main development system so I see these scary warnings all the time, so I’d prefer for this to be merged or the relevant warning disabled (for that gcc).

    Edit: tested that this makes the warnings disappear here.

  18. in src/wallet/rpcwallet.cpp:44 in c14d580003 outdated
    40@@ -41,6 +41,8 @@
    41 
    42 #include <functional>
    43 
    44+#include <boost/optional.hpp>
    


    laanwj commented at 7:33 pm on January 30, 2019:
    I’d mildly prefer to redirect this through our optional.h, define our own make_optional like the Option<T> itself instead of boost appearing here direclty.
  19. gmaxwell commented at 7:55 pm on January 30, 2019: contributor
    Found this PR after seeing the scary warnings… maybe-uninitialized is a pretty potent warning, I wouldn’t want to disable it unless it was only on old compilers.
  20. MarcoFalke commented at 8:03 pm on January 30, 2019: member
    Hmm, one of the warnings disappears when going from gcc7 to gcc8?
  21. practicalswift commented at 8:28 pm on January 30, 2019: contributor
    utACK c14d5800032158f43b5d790f89f3d7a1fc18e1e7 modulo @laanwj’s nit regarding optional.h
  22. Remove 'boost::optional'-related gcc warnings 2d483142a7
  23. hebasto force-pushed on Jan 30, 2019
  24. hebasto commented at 8:46 pm on January 30, 2019: member
    @laanwj’s nit has been addressed.
  25. practicalswift commented at 8:54 pm on January 30, 2019: contributor
    utACK 2d483142a7051389afe74c57a216843e6306f1a8
  26. laanwj commented at 9:43 pm on January 30, 2019: member
    utACK 2d483142a7051389afe74c57a216843e6306f1a8
  27. laanwj merged this on Jan 30, 2019
  28. laanwj closed this on Jan 30, 2019

  29. laanwj referenced this in commit cb77dc820f on Jan 30, 2019
  30. hebasto deleted the branch on Jan 30, 2019
  31. laanwj referenced this in commit b30a1f3e39 on Feb 5, 2020
  32. sidhujag referenced this in commit 7b273400f2 on Feb 9, 2020
  33. deadalnix referenced this in commit 816f2c7bbd on Apr 11, 2020
  34. ftrader referenced this in commit 6eea1e105e on Oct 16, 2020
  35. sidhujag referenced this in commit 3f4c6b911e on Nov 10, 2020
  36. DrahtBot locked this on Dec 16, 2021

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-04 06:12 UTC

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