New `maybe-uninitialized` warnings - probably false positives #18198

issue elichai opened this issue on February 23, 2020
  1. elichai commented at 3:07 PM on February 23, 2020: contributor

    With GCC 9.2 and latest master(ab9de435880c9d77e4137b65050591ef2d14f809) I'm getting these warnings:

    interfaces/chain.cpp: In member function 'virtual Optional<int> interfaces::{anonymous}::LockImpl::findFork(const uint256&, Optional<int>*)':                                                                                                                                   
    interfaces/chain.cpp:140:16: warning: '*((void*)&<anonymous> +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]                                                                                                                                            
      140 |         return nullopt;                                                                                                         
          |                ^~~~~~~                                     
    interfaces/chain.cpp: In member function 'virtual Optional<int> interfaces::{anonymous}::LockImpl::getHeight()':                        
    interfaces/chain.cpp:140:16: warning: '*((void*)&<anonymous> +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]                                                                                                                                            
      140 |         return nullopt;                                                                                                         
          |                ^~~~~~~                                                                                                          
    interfaces/chain.cpp: In member function 'virtual Optional<int> interfaces::{anonymous}::LockImpl::findLocatorFork(const CBlockLocator&)':
    interfaces/chain.cpp:140:16: warning: '*((void*)&<anonymous> +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]    
      140 |         return nullopt;                                  
          |                ^~~~~~~                                  
    interfaces/chain.cpp: In member function 'virtual Optional<int> interfaces::{anonymous}::LockImpl::findFirstBlockWithTimeAndHeight(int64_t, int, uint256*)':
    interfaces/chain.cpp:140:16: warning: '*((void*)&<anonymous> +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]    
      140 |         return nullopt;                                    
    

    Seems to be related to #18052 but with less clear fix (replacing nullopt with MakeOptional(false...) is a bad fix IMHO)

    Note, I don't see these warnings when compiling with clang 9.0.1

  2. elichai added the label Bug on Feb 23, 2020
  3. kristapsk commented at 4:17 PM on February 23, 2020: contributor

    Can't reproduce, don't have them with gcc (Gentoo 9.2.0-r2 p3) 9.2.0.

  4. elichai commented at 4:26 PM on February 23, 2020: contributor

    Can't reproduce, don't have them with gcc (Gentoo 9.2.0-r2 p3) 9.2.0.

    I have gcc (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130 and tried full cleaning and I still get them

  5. MarcoFalke removed the label Bug on Feb 24, 2020
  6. MarcoFalke added the label Brainstorming on Feb 24, 2020
  7. hebasto commented at 3:12 PM on March 20, 2020: member

    @elichai

    ... replacing nullopt with MakeOptional(false...) is a bad fix IMHO

    What reasons for?

  8. elichai commented at 2:24 PM on March 21, 2020: contributor

    What reasons for?

    Because it's less obvious what it's doing. return nullopt; is obvious. but return MakeOptional(false, object{}) is less obvious, does it creates a value? does it calls the "object" constructor?. When you read the docs you can understand it but it's one of those things that if you haven't done in a while you need to open the docs to check what's what. which IMHO is a decrease in readability.

  9. elichai commented at 2:34 PM on April 29, 2020: contributor

    This no longer happens on gcc 9.3.0(gcc (Arch Linux 9.3.0-1) 9.3.0) Tested both master(af2ec6b03745cf408f169cfbd74e3380a69975e0) and the commit where I saw it last time and the warning is no longer there

    I don't have GCC 9.2.0 to check with that, but because no-one else says they saw that warning I'll close this

  10. elichai closed this on Apr 29, 2020

  11. MarcoFalke locked this on Feb 15, 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: 2026-04-17 09:14 UTC

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