refactor: Avoid unused-variable warning in init.cpp #29968

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2404-init- changing 1 files +2 −4
  1. maflcko commented at 8:18 am on April 26, 2024: member
  2. DrahtBot commented at 8:18 am on April 26, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK TheCharlatan
    Stale ACK pinheadmz, hebasto

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29432 (Stratum v2 Template Provider (take 3) by Sjors)
    • #25972 (build: no-longer disable WARN_CXXFLAGS when CXXFLAGS is set by fanquake)

    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.

  3. DrahtBot added the label Refactoring on Apr 26, 2024
  4. maflcko commented at 8:52 am on April 26, 2024: member
    @fanquake Can you cherry-pick this into your pull, to confirm that it also works for you? (I only tested it locally)
  5. fanquake commented at 8:54 am on April 26, 2024: member
    Pulled it in
  6. hebasto approved
  7. hebasto commented at 9:53 am on April 26, 2024: member
    ACK fa5ba429a71eb81848560b4a547d1717efd33593, tested on Ubuntu 24.04 with -Wall.
  8. in src/init.cpp:1304 in fa5ba429a7 outdated
    1300@@ -1301,7 +1301,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
    1301         }
    1302     }
    1303 
    1304-    for (const auto &port_option : std::vector<std::pair<std::string, bool>>{
    1305+    for (const auto& [arg, unix] : std::vector<std::pair<std::string, bool>>{
    


    laanwj commented at 12:00 pm on April 26, 2024:

    ACK on improving the syntax, but it seems a matter of time before the compiler again becomes smart enough to see this variable is unused? Mayb eadd

    0(void)unix;
    

    to the !HAVE_SOCKADDR_UN path just in case?

  9. maflcko force-pushed on Apr 26, 2024
  10. in src/init.cpp:1320 in fa141d27cc outdated
    1314@@ -1315,20 +1315,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
    1315         {"-zmqpubrawtx",            true},
    1316         {"-zmqpubsequence",         true}
    1317     }) {
    1318-        const std::string arg{port_option.first};
    1319-        const bool unix{port_option.second};
    1320+#if HAVE_SOCKADDR_UN
    1321+#else
    1322+        unix = false;
    


    laanwj commented at 12:42 pm on April 26, 2024:

    Now you’re assigning a value that isn’t used, i think that will generate a warning too. Doesn’t the suggested (void)unix; work to simulate a read?

    Or maybe, even check it and raise an error. Eg.

    0if (unix) {
    1    Error("This platform does not support UNIX sockets.");
    2}
    

    maflcko commented at 1:48 pm on April 26, 2024:

    Or maybe, even check it and raise an error. Eg.

    Sure, happy to close this pull if someone creates an alternative, but I’ll probably leave this pull as-is

  11. maflcko force-pushed on Apr 26, 2024
  12. DrahtBot added the label CI failed on Apr 26, 2024
  13. DrahtBot commented at 12:49 pm on April 26, 2024: contributor

    🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the documentation.

    Possibly this is due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    Leave a comment here, if you need help tracking down a confusing failure.

    Debug: https://github.com/bitcoin/bitcoin/runs/24297453221

  14. DrahtBot removed the label CI failed on Apr 26, 2024
  15. pinheadmz approved
  16. pinheadmz commented at 5:10 pm on April 30, 2024: member

    ACK fa2353d9c3ff68995e7478b9b80dcdb1fc638a53

    Confirmed the warning on master by setting -Wall and then forcing HAVE_SOCKADDR_UN = 0 in configure.ac. This patch fixes the warning in a clean way. I dunno if (void)unix; needs an explanatory comment or if thats a recognizable pattern for this kind of thing.

    Thanks again @maflcko for cleaning up my mess 😬

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA256
     2
     3ACK fa2353d9c3ff68995e7478b9b80dcdb1fc638a53
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmYxJW0ACgkQ5+KYS2KJ
     7yTpXqg//VS2W2FATmVSHha7wDo/Kaj3rFAIH9nxlKr9tEeZCda2DCsY0bD8IYi53
     81mfvrPhEpwhyv85Rztx35PEnGz7mvwWcL62diicx+qYTmy6DtctwzvRN9SKatF/V
     9xIVm8aPVHrcczlw30vvturmiZDvP0iFg8n6LpjZZvHmqiPYAQQ/wP63iaaYSdARY
    10iYb1cV5sZgh80Q6Tiy08/qTUyWxgwE50LXbAeyu7ZPx9yY6jOWxL3LP1o+0ZTkbH
    111SWYjrdC2S+NxbMf5PfiT3VezA5Lezk90wZzgUjuPexzZChk1mZTh+XKn4RLTSGy
    12xqLAu9TPMylmuEsMb70g0YLsZHFdQI2k84xwZwmyXhLN77zWncFNmJiXQbmJoSWv
    13+BSGg/2tROOHs/KtbY50HVnVv1Fv5FPlg5llRH0EpaeFGlYn7pHt2x61uDjf83Wy
    14+dQU2Cx+L2AgioC0CD6tQzuSaklweFQw+t8wRVnC8gyS2ftBT99TB7/qCB0h0/vq
    15lypmobdOofSfEea/i13L91vGxyv7F9rw7SimzbPMPUaYzZs6OA3c9rLbcabPbja/
    16YdygzdYZKmTUKeExMNjCGyxRp+swIDTPwT3Ca9N00+vN+eVzfIbSDoXaVj7ZWzIO
    17aSPqUMdCjLiqAJ/AcFSBKFLUTCcg+99rcfA4/kkduQxJaGdNF04=
    18=Pu5n
    19-----END PGP SIGNATURE-----
    

    pinheadmz’s public key is on keybase

  17. DrahtBot requested review from hebasto on Apr 30, 2024
  18. hebasto approved
  19. hebasto commented at 5:37 pm on April 30, 2024: member
    re-ACK fa2353d9c3ff68995e7478b9b80dcdb1fc638a53.
  20. fanquake commented at 8:06 am on May 1, 2024: member

    Could be:

     0diff --git a/src/init.cpp b/src/init.cpp
     1index 4d7638cd6e..ebfcb9cf8e 100644
     2--- a/src/init.cpp
     3+++ b/src/init.cpp
     4@@ -1312,7 +1312,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
     5         {"-zmqpubsequence",         true}
     6     }) {
     7         const std::string arg{port_option.first};
     8-        const bool unix{port_option.second};
     9+        [[maybe_unused]] const bool unix{port_option.second};
    10         for (const std::string& socket_addr : args.GetArgs(arg)) {
    11             std::string host_out;
    12             uint16_t port_out{0};
    

    Avoids the worry about future compilers, and (void)blah which isn’t explanatory

  21. refactor: Avoid unused-variable warning in init.cpp fa9abf9688
  22. maflcko force-pushed on May 2, 2024
  23. maflcko commented at 10:51 am on May 2, 2024: member

    Avoids the worry about future compilers, and (void)blah which isn’t explanatory

    I think (void)blah; is well understood to mean this (to both code readers and compilers), but [[maybe_unused]] seems fine as well. Switched to that.

  24. TheCharlatan approved
  25. TheCharlatan commented at 1:00 pm on May 2, 2024: contributor
    ACK fa9abf968840745e428a86a9545aaa6c923415e2
  26. DrahtBot requested review from hebasto on May 2, 2024
  27. DrahtBot requested review from pinheadmz on May 2, 2024
  28. fanquake merged this on May 2, 2024
  29. fanquake closed this on May 2, 2024

  30. maflcko deleted the branch on May 2, 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-12-03 18:12 UTC

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