compiler warning on building src/test/test_bitcoin-validation_chainstate_tests.o #23101

issue katesalazar openend this issue on September 26, 2021
  1. katesalazar commented at 5:11 pm on September 26, 2021: contributor

    Is your feature request related to a problem? Please describe.

    Warning on building using g++ 8.3.

     0 1 In file included from ./txdb.h:11,
     1 2                  from ./validation.h:26,
     2 3                  from ./test/util/chainstate.h:13,
     3 4                  from test/validation_chainstate_tests.cpp:11:
     4 5 ./chain.h: In member function ‘void validation_chainstate_tests::chainstate_update_tip::test_method()’:
     5 6 ./chain.h:422:27: warning: ‘background_cs’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     6 7          return vChain.size() > 0 ? vChain[vChain.size() - 1] : nullptr;
     7 8                 ~~~~~~~~~~~^~
     8 9 test/validation_chainstate_tests.cpp:109:18: note: ‘background_cs’ was declared here
     910      CChainState* background_cs;
    1011                   ^~~~~~~~~~~~~
    1112
    

    Describe the solution you’d like

    Able to build without warnings.

    Describe alternatives you’ve considered

    N/A.

    Additional context

    cd src/ && make test/test_bitcoin-validation_chainstate_tests.o

    Bisecting this warning, I ended up in revision 673a5bd3377929a0 by @jamesob.

    Thank you very much and please excuse the noise.

  2. katesalazar added the label Feature on Sep 26, 2021
  3. hebasto removed the label Feature on Sep 26, 2021
  4. MarcoFalke commented at 7:36 am on September 27, 2021: member

    Can be fixed with:

     0diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp
     1index 726c9ebbb..9bb08f774 100644
     2--- a/src/test/validation_chainstate_tests.cpp
     3+++ b/src/test/validation_chainstate_tests.cpp
     4@@ -107,20 +107,21 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
     5 
     6     curr_tip = ::g_best_block;
     7 
     8-    CChainState* background_cs;
     9-
    10     BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2);
    11-    for (CChainState* cs : chainman.GetAll()) {
    12-        if (cs != &chainman.ActiveChainstate()) {
    13-            background_cs = cs;
    14+
    15+    CChainState& background_cs{*[&] {
    16+        for (CChainState* cs : chainman.GetAll()) {
    17+            if (cs != &chainman.ActiveChainstate()) {
    18+                return cs;
    19+            }
    20         }
    21-    }
    22-    BOOST_CHECK(background_cs);
    23+        assert(false);
    24+    }()};
    25 
    26     // Create a block to append to the validation chain.
    27     std::vector<CMutableTransaction> noTxns;
    28     CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
    29-    CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, *background_cs);
    30+    CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, background_cs);
    31     auto pblock = std::make_shared<const CBlock>(validation_block);
    32     BlockValidationState state;
    33     CBlockIndex* pindex = nullptr;
    34@@ -133,15 +134,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
    35         LOCK(::cs_main);
    36         bool checked = CheckBlock(*pblock, state, chainparams.GetConsensus());
    37         BOOST_CHECK(checked);
    38-        bool accepted = background_cs->AcceptBlock(
    39+        bool accepted = background_cs.AcceptBlock(
    40             pblock, state, &pindex, true, nullptr, &newblock);
    41         BOOST_CHECK(accepted);
    42     }
    43     // UpdateTip is called here
    44-    bool block_added = background_cs->ActivateBestChain(state, pblock);
    45+    bool block_added = background_cs.ActivateBestChain(state, pblock);
    46 
    47     // Ensure tip is as expected
    48-    BOOST_CHECK_EQUAL(background_cs->m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
    49+    BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
    50 
    51     // g_best_block should be unchanged after adding a block to the background
    52     // validation chain.
    
  5. katesalazar commented at 3:21 pm on September 27, 2021: contributor
    It went away!
  6. meshcollider commented at 9:54 am on September 29, 2021: contributor
    @MarcoFalke want to PR the fix?
  7. MarcoFalke referenced this in commit fa4d0aacf2 on Sep 29, 2021
  8. MarcoFalke closed this on Oct 12, 2021

  9. MarcoFalke referenced this in commit 8df7eee5e1 on Oct 12, 2021
  10. rebroad referenced this in commit a2a5392d3c on Oct 13, 2021
  11. janus referenced this in commit b7761d1f9b on Nov 11, 2021
  12. DrahtBot locked this on Oct 30, 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-11-17 09:12 UTC

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