GCC 13: -Wdangling-reference output #26926

issue fanquake openend this issue on January 20, 2023
  1. fanquake commented at 10:17 am on January 20, 2023: member

    New warnings currently emitted by the shortly-to-be-released GCC 13. This is building master (eebc24bfc6d2d809952e27c7fe269452f319455f), using GCC gcc (GCC) 13.0.0 20230115 (Red Hat 13.0.0-0):

     0external_signer.cpp: In static member function ‘static bool ExternalSigner::Enumerate(const std::string&, std::vector<ExternalSigner>&, std::string)’:
     1external_signer.cpp:33:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2   33 |         const UniValue& error = find_value(signer, "error");
     3      |                         ^~~~~
     4external_signer.cpp:33:43: note: the temporary was destroyed at the end of the full expression ‘find_value((* & signer), std::__cxx11::basic_string<char>(((const char*)"error"), std::allocator<char>())) 5   33 |         const UniValue& error = find_value(signer, "error");
     6      |                                 ~~~~~~~~~~^~~~~~~~~~~~~~~~~
     7external_signer.cpp:41:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     8   41 |         const UniValue& fingerprint = find_value(signer, "fingerprint");
     9      |                         ^~~~~~~~~~~
    10external_signer.cpp:41:49: note: the temporary was destroyed at the end of the full expression ‘find_value((* & signer), std::__cxx11::basic_string<char>(((const char*)"fingerprint"), std::allocator<char>()))11   41 |         const UniValue& fingerprint = find_value(signer, "fingerprint");
    12      |                                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
    13external_signer.cpp:53:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    14   53 |         const UniValue& model_field = find_value(signer, "model");
    15      |                         ^~~~~~~~~~~
    16external_signer.cpp:53:49: note: the temporary was destroyed at the end of the full expression ‘find_value((* & signer), std::__cxx11::basic_string<char>(((const char*)"model"), std::allocator<char>()))17   53 |         const UniValue& model_field = find_value(signer, "model");
    18      |                                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~
    
     0rpc/rawtransaction_util.cpp: In function ‘CMutableTransaction ConstructTransaction(const UniValue&, const UniValue&, const UniValue&, std::optional<bool>)’:
     1rpc/rawtransaction_util.cpp:55:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2   55 |         const UniValue& vout_v = find_value(o, "vout");
     3      |                         ^~~~~~
     4rpc/rawtransaction_util.cpp:55:44: note: the temporary was destroyed at the end of the full expression ‘find_value((* & o), std::__cxx11::basic_string<char>(((const char*)"vout"), std::allocator<char>())) 5   55 |         const UniValue& vout_v = find_value(o, "vout");
     6      |                                  ~~~~~~~~~~^~~~~~~~~~~
     7rpc/rawtransaction_util.cpp:73:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     8   73 |         const UniValue& sequenceObj = find_value(o, "sequence");
     9      |                         ^~~~~~~~~~~
    10rpc/rawtransaction_util.cpp:73:49: note: the temporary was destroyed at the end of the full expression ‘find_value((* & o), std::__cxx11::basic_string<char>(((const char*)"sequence"), std::allocator<char>()))11   73 |         const UniValue& sequenceObj = find_value(o, "sequence");
    12      |                                       ~~~~~~~~~~^~~~~~~~~~~~~~~
    
     0bitcoin-cli.cpp: In function ‘UniValue ConnectAndCallRPC(BaseRequestHandler*, const std::string&, const std::vector<std::__cxx11::basic_string<char> >&, const std::optional<std::__cxx11::basic_string<char> >&)’:
     1bitcoin-cli.cpp:853:33: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2  853 |                 const UniValue& error = find_value(response, "error");
     3      |                                 ^~~~~
     4bitcoin-cli.cpp:853:51: note: the temporary was destroyed at the end of the full expression ‘find_value(response, std::__cxx11::basic_string<char>(((const char*)"error"), std::allocator<char>())) 5  853 |                 const UniValue& error = find_value(response, "error");
     6      |                                         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
     7bitcoin-cli.cpp: In function ‘void ParseError(const UniValue&, std::string&, int&)’:
     8bitcoin-cli.cpp:881:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     9  881 |         const UniValue& err_code = find_value(error, "code");
    10      |                         ^~~~~~~~
    11bitcoin-cli.cpp:881:46: note: the temporary was destroyed at the end of the full expression ‘find_value((* & error), std::__cxx11::basic_string<char>(((const char*)"code"), std::allocator<char>()))12  881 |         const UniValue& err_code = find_value(error, "code");
    13      |                                    ~~~~~~~~~~^~~~~~~~~~~~~~~
    14bitcoin-cli.cpp:882:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    15  882 |         const UniValue& err_msg = find_value(error, "message");
    16      |                         ^~~~~~~
    17bitcoin-cli.cpp:882:45: note: the temporary was destroyed at the end of the full expression ‘find_value((* & error), std::__cxx11::basic_string<char>(((const char*)"message"), std::allocator<char>()))18  882 |         const UniValue& err_msg = find_value(error, "message");
    19      |                                   ~~~~~~~~~~^~~~~~~~~~~~~~~~~~
    20bitcoin-cli.cpp: In function ‘void GetWalletBalances(UniValue&)’:
    21bitcoin-cli.cpp:909:21: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    22  909 |     const UniValue& wallets = find_value(listwallets, "result");
    23      |                     ^~~~~~~
    24bitcoin-cli.cpp:909:41: note: the temporary was destroyed at the end of the full expression ‘find_value(listwallets, std::__cxx11::basic_string<char>(((const char*)"result"), std::allocator<char>()))25  909 |     const UniValue& wallets = find_value(listwallets, "result");
    26      |                               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
    27bitcoin-cli.cpp:916:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    28  916 |         const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"];
    29      |                         ^~~~~~~
    30bitcoin-cli.cpp:916:86: note: the temporary was destroyed at the end of the full expression ‘(&(& find_value(getbalances, std::__cxx11::basic_string<char>(((const char*)"result"), std::allocator<char>())))->UniValue::operator[](std::__cxx11::basic_string<char>(((const char*)"mine"), std::allocator<char>())))->UniValue::operator[](std::__cxx11::basic_string<char>(((const char*)"trusted"), std::allocator<char>()))31  916 |         const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"];
    32      |                                                                                      ^
    33bitcoin-cli.cpp: In function ‘int CommandLineRPC(int, char**)’:
    34bitcoin-cli.cpp:1163:29: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    35 1163 |             const UniValue& error{find_value(getnewaddress, "error")};
    36      |                             ^~~~~
    37bitcoin-cli.cpp:1163:45: note: the temporary was destroyed at the end of the full expression ‘find_value(getnewaddress, std::__cxx11::basic_string<char>(((const char*)"error"), std::allocator<char>()))38 1163 |             const UniValue& error{find_value(getnewaddress, "error")};
    39      |                                   ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
    40bitcoin-cli.cpp:1188:29: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    41 1188 |             const UniValue& error = find_value(reply, "error");
    42      |                             ^~~~~
    43bitcoin-cli.cpp:1188:47: note: the temporary was destroyed at the end of the full expression ‘find_value(reply, std::__cxx11::basic_string<char>(((const char*)"error"), std::allocator<char>()))44 1188 |             const UniValue& error = find_value(reply, "error");
    45      |                                     ~~~~~~~~~~^~~~~~~~~~~~~~~~
    
     0rpc/mining.cpp: In lambda function:
     1rpc/mining.cpp:606:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2  606 |         const UniValue& modeval = find_value(oparam, "mode");
     3      |                         ^~~~~~~
     4rpc/mining.cpp:606:45: note: the temporary was destroyed at the end of the full expression ‘find_value((* & oparam), std::__cxx11::basic_string<char>(((const char*)"mode"), std::allocator<char>())) 5  606 |         const UniValue& modeval = find_value(oparam, "mode");
     6      |                                   ~~~~~~~~~~^~~~~~~~~~~~~~~~
     7rpc/mining.cpp:619:29: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     8  619 |             const UniValue& dataval = find_value(oparam, "data");
     9      |                             ^~~~~~~
    10rpc/mining.cpp:619:49: note: the temporary was destroyed at the end of the full expression ‘find_value((* & oparam), std::__cxx11::basic_string<char>(((const char*)"data"), std::allocator<char>()))11  619 |             const UniValue& dataval = find_value(oparam, "data");
    12      |                                       ~~~~~~~~~~^~~~~~~~~~~~~~~~
    13rpc/mining.cpp:646:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    14  646 |         const UniValue& aClientRules = find_value(oparam, "rules");
    15      |                         ^~~~~~~~~~~~
    16rpc/mining.cpp:646:50: note: the temporary was destroyed at the end of the full expression ‘find_value((* & oparam), std::__cxx11::basic_string<char>(((const char*)"rules"), std::allocator<char>()))17  646 |         const UniValue& aClientRules = find_value(oparam, "rules");
    18      |                                        ~~~~~~~~~~^~~~~~~~~~~~~~~~~
    
     0test/interfaces_tests.cpp: In member function ‘void interfaces_tests::findCommonAncestor::test_method()’:
     1test/interfaces_tests.cpp:101:19: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2  101 |     const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
     3      |                   ^~~~~~
     4In file included from ./util/system.h:21,
     5                 from ./test/util/setup_common.h:19,
     6                 from test/interfaces_tests.cpp:9:
     7./sync.h:302:96: note: the temporary was destroyed at the end of the full expression ‘<lambda closure object>interfaces_tests::findCommonAncestor::test_method()::<lambda()>{((interfaces_tests::findCommonAncestor*)this)}.interfaces_tests::findCommonAncestor::test_method()::<lambda()>() 8  302 | #define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
     9      |                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
    10test/interfaces_tests.cpp:101:28: note: in expansion of macro ‘WITH_LOCK’
    11  101 |     const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
    12      |                            ^~~~~~~~~
    
     0test/system_tests.cpp: In member function ‘void system_tests::run_command::test_method()’:
     1test/system_tests.cpp:48:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2   48 |         const UniValue& success = find_value(result, "success");
     3      |                         ^~~~~~~
     4test/system_tests.cpp:48:45: note: the temporary was destroyed at the end of the full expression ‘find_value(result, std::__cxx11::basic_string<char>(((const char*)"success"), std::allocator<char>())) 5   48 |         const UniValue& success = find_value(result, "success");
     6      |                                   ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
     7test/system_tests.cpp:96:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     8   96 |         const UniValue& success = find_value(result, "success");
     9      |                         ^~~~~~~
    10test/system_tests.cpp:96:45: note: the temporary was destroyed at the end of the full expression ‘find_value(result, std::__cxx11::basic_string<char>(((const char*)"success"), std::allocator<char>()))11   96 |         const UniValue& success = find_value(result, "success");
    12      |                                   ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
    
  2. maflcko commented at 10:33 am on January 20, 2023: member
    This is a compiler bug, so might be best to report to them?
  3. maflcko added the label Upstream on Jan 20, 2023
  4. maflcko added the label Questions and Help on Jan 20, 2023
  5. fanquake commented at 11:16 am on January 24, 2023: member
    Hopefully GCC 13 wont ship with any false positives, as this upstream report is tagged P1: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532. If it does/anyone reports this in future, we can point back to this issue.
  6. fanquake closed this on Jan 24, 2023

  7. achow101 commented at 5:28 pm on May 8, 2023: member
    Getting these errors with gcc 13.1.1
  8. achow101 reopened this on May 8, 2023

  9. maflcko commented at 8:32 am on May 9, 2023: member

    See #27605 for a code change. An alternative might be to locally or globally disable the warning.

    For testing, one can use a fresh install of Fedora 38:

    0dnf install gcc-c++ libtool make autoconf automake python3 clang llvm lbzip2 patch xz cmake     curl wget htop git vim ccache   libevent-devel boost-devel qt5-qttools-devel qt5-qtbase-devel   -y && git clone https://github.com/bitcoin/bitcoin.git   ./bitcoin-core && cd bitcoin-core &&  ./autogen.sh &&  ./configure  && make -j $(nproc)
    
  10. maflcko added the label Build system on May 9, 2023
  11. maflcko removed the label Questions and Help on May 9, 2023
  12. achow101 referenced this in commit e0a70c5b4f on May 10, 2023
  13. fanquake commented at 5:06 pm on May 10, 2023: member
    Closing, now that #27605 has been merged.
  14. fanquake closed this on May 10, 2023

  15. bitcoin locked this on May 9, 2024

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-24 00:12 UTC

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