Fix Windows build with –enable-werror #20586

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:201206-win changing 4 files +15 −7
  1. hebasto commented at 10:02 pm on December 6, 2020: member

    This PR makes possible to cross-compile Windows build with --enable-werror --enable-suppress-external-warnings. Some problems are fixed, others are silenced.

    Also --enable-werror is enabled for Cirrus CI Windows build (the last one on Cirrus CI without --enable-werror).

  2. hebasto commented at 10:03 pm on December 6, 2020: member
  3. DrahtBot added the label Build system on Dec 6, 2020
  4. DrahtBot added the label GUI on Dec 6, 2020
  5. DrahtBot commented at 10:48 pm on December 6, 2020: member

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

    Conflicts

    No conflicts as of last run.

  6. MarcoFalke removed the label GUI on Dec 7, 2020
  7. in src/fs.cpp:161 in 06ff47560e outdated
    147@@ -148,7 +148,10 @@ std::string get_filesystem_error_message(const fs::filesystem_error& e)
    148 #ifdef __GLIBCXX__
    149 
    150 // reference: https://github.com/gcc-mirror/gcc/blob/gcc-7_3_0-release/libstdc%2B%2B-v3/include/std/fstream#L270
    151-
    152+#if defined(__GNUC__) && !defined(__clang__)
    153+#pragma GCC diagnostic push
    154+#pragma GCC diagnostic ignored "-Wswitch"
    155+#endif
    156 static std::string openmodeToStr(std::ios_base::openmode mode)
    


    vasild commented at 9:53 am on December 7, 2020:
    This will disable -Wswitch for any GCC compiler (even latest on Linux). Shouldn’t we restrict that somehow? Maybe check if WIN32 is defined or for a specific GCC version?


    vasild commented at 12:57 pm on December 7, 2020:
    Oh, it is already inside #ifdef WIN32, sorry for the noise.

    laanwj commented at 6:18 am on August 27, 2021:
    I was about to ask this, but yes, it is already a (temporary, I guess) WIN32-specific workaround.
  8. in configure.ac:438 in 06ff47560e outdated
    396+
    397+  dnl -Wreturn-type is broken in GCC for MinGW-w64.
    398+  dnl https://sourceforge.net/p/mingw-w64/bugs/306/
    399+  AX_CHECK_COMPILE_FLAG([-Werror=return-type], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"], [], [$CXXFLAG_WERROR],
    400+                        [AC_LANG_SOURCE([[#include <cassert>
    401+                                          int f(){ assert(false); }]])])
    


    vasild commented at 9:55 am on December 7, 2020:

    This is good and will work fine.

    I am just curious, does that mingw bug 306 manifest if assert(false) is replaced with abort()?


    hebasto commented at 12:25 pm on December 7, 2020:
    Did not dive in details, but it seems to be dealing with an internal attribute of noreturn.
  9. laanwj commented at 12:52 pm on December 7, 2020: member

    I’m a bit divided on whether building on every platform/compiler combination ‘with -Werror’ is actually a goal of the project. I mean, I think this is impossible, and will result in a lot of warning fixing for the sake of warning fixing.

    In general Werror is a curse.

  10. MarcoFalke commented at 1:06 pm on December 7, 2020: member
    Tend to agree with @laanwj, especially if the workarounds will make already hard to understand files like fs.cpp even more verbose.
  11. vasild approved
  12. vasild commented at 1:10 pm on December 7, 2020: member

    ACK 06ff4756

    Sometimes important warnings are emitted only on some platforms, so I think it is good to use -Werror on as most platforms as possible.

    If keeping Windows builds warning-free turns out to be too big burden then the NO_WERROR=1 can be added back.

  13. hebasto commented at 1:11 pm on December 7, 2020: member

    I’m a bit divided on whether building on every platform/compiler combination ‘with -Werror’ is actually a goal of the project. I mean, I think this is impossible, and will result in a lot of warning fixing for the sake of warning fixing.

    In general Werror is a curse.

    Tend to agree with @laanwj, especially if the workarounds will make already hard to understand files like fs.cpp even more verbose.

    Fair enough.

    The goal of this PR (combined with #20544) is to prevent changes that introduce new warnings.

    Anyway, feel free to close this.

  14. DrahtBot commented at 4:09 pm on December 9, 2020: member

    🕵️ @practicalswift has been requested to review this pull request as specified in the REVIEWERS file.

  15. practicalswift commented at 4:22 pm on December 9, 2020: contributor
    Concept ACK
  16. hebasto force-pushed on Dec 10, 2020
  17. hebasto commented at 12:06 pm on December 10, 2020: member

    Updated 06ff47560ecb1d6a80e9fbd2f169f6ed8f31c464 -> 926f6d82a31b2d2c82b830b2b672fa38890b8590 (pr20586.01 -> pr20586.02, diff). @MarcoFalke

    Tend to agree with @laanwj, especially if the workarounds will make already hard to understand files like fs.cpp even more verbose.

    Only one-line change in fs.cpp now.

  18. in src/fs.cpp:154 in 926f6d82a3 outdated
    151+// reference: https://github.com/gcc-mirror/gcc/blob/releases%2Fgcc-7.3.0/libstdc%2B%2B-v3/include/std/fstream#L270
    152 
    153 static std::string openmodeToStr(std::ios_base::openmode mode)
    154 {
    155-    switch (mode & ~std::ios_base::ate) {
    156+    switch (static_cast<int>(mode & ~std::ios_base::ate)) { // casting is required to suppress -Wswitch warnings
    


    vasild commented at 1:08 pm on December 10, 2020:
    std::ios_base::ate and friends are defined as unsigned int on my platform. What is the warning that this tries to fix?

    hebasto commented at 1:47 pm on December 10, 2020:

    std::ios_base::ate and friends are defined as unsigned int on my platform.

    https://github.com/gcc-mirror/gcc/blob/releases/gcc-7.3.0/libstdc%2B%2B-v3/include/bits/ios_base.h#L111-L122

    What is the warning that this tries to fix?

    https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Warning-Options.html#Warning-Options:

    -Wswitchcase labels outside the enumeration range also provoke warnings when this option is used (even if there is a default label).


    vasild commented at 2:21 pm on December 10, 2020:

    Ok, we are fine because if some of the case values is out of the range of int, then we would get a warning:

    0void f(unsigned int x)
    1{
    2    const unsigned int y = 3000000000U;
    3
    4    switch (static_cast<int>(x)) { 
    5    case y:
    6        std::cout << "foo\n";
    7        break;
    8    } 
    9}
    
    0error: case value evaluates to 3000000000, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
    

    from clang 12 with -Wall


    luke-jr commented at 1:03 am on December 14, 2020:

    NACK, the standard doesn’t guarantee this fits in an int

    Can you use a pragma to disable the warning here?


    hebasto commented at 5:11 pm on December 19, 2020:
    Done.
  19. vasild approved
  20. vasild commented at 2:22 pm on December 10, 2020: member
    ACK 926f6d82a31b2d2c82b830b2b672fa38890b8590
  21. luke-jr changes_requested
  22. hebasto force-pushed on Dec 19, 2020
  23. hebasto commented at 5:10 pm on December 19, 2020: member

    Reverted back 06ff47560ecb1d6a80e9fbd2f169f6ed8f31c464 <- 926f6d82a31b2d2c82b830b2b672fa38890b8590 (pr20586.01 <- pr20586.02) as was requested by @luke-jr.

    This variant has been already ACKed by @vasild.

  24. DrahtBot added the label Needs rebase on Feb 8, 2021
  25. DrahtBot removed the label Needs rebase on Feb 19, 2021
  26. practicalswift commented at 7:37 am on March 6, 2021: contributor

    cr ACK 06ff47560ecb1d6a80e9fbd2f169f6ed8f31c464: patch looks correct

    FWIW, having this in master would have prevented the issue #21355 pre-merge :)

  27. Fix Windows build with --enable-werror on Ubuntu Focal c713bb2b24
  28. ci: Make Cirrus CI Windows build with --enable-werror b367745cfe
  29. in src/fs.cpp:159 in 83b4c4f96b outdated
    147@@ -148,7 +148,10 @@ std::string get_filesystem_error_message(const fs::filesystem_error& e)
    148 #ifdef __GLIBCXX__
    149 
    150 // reference: https://github.com/gcc-mirror/gcc/blob/gcc-7_3_0-release/libstdc%2B%2B-v3/include/std/fstream#L270
    151-
    152+#if defined(__GNUC__) && !defined(__clang__)
    153+#pragma GCC diagnostic push
    154+#pragma GCC diagnostic ignored "-Wswitch"
    


    MarcoFalke commented at 7:40 am on March 6, 2021:

    Is this commit " Fix Windows build with –enable-werror on Ubuntu Bionic (gcc 7.5) " still needed?

    We no longer use mingw on bionic (only focal)


    hebasto commented at 7:53 am on March 6, 2021:

    Right. #21036 made it possible.

    Going to rebase the pr and remove that commit.


    hebasto commented at 8:20 am on March 6, 2021:

    @MarcoFalke It is still required to prevent -Werror=switch warnings on Focal.

    Therefore, technically, no changes are required in the patch.

  30. hebasto force-pushed on Apr 13, 2021
  31. hebasto commented at 7:25 am on April 13, 2021: member

    Updated 06ff47560ecb1d6a80e9fbd2f169f6ed8f31c464 -> b367745cfe19f6de3f44b3adc90fa08e36e44bb6 (pr20586.01 -> pr20586.03):

  32. vasild approved
  33. vasild commented at 8:45 am on April 13, 2021: member
    ACK b367745cfe19f6de3f44b3adc90fa08e36e44bb6
  34. jarolrod commented at 5:40 am on June 6, 2021: member

    ACK b367745cfe19f6de3f44b3adc90fa08e36e44bb6

    Tested on Linux cross-compiling to Windows passing --enable-werror to configure

    Master:

    0script/standard.cpp:215:26: error: control reaches end of non-void function [-Werror=return-type]
    1  215 |     std::vector<valtype> vSolutions;
    

    PR: Builds fine and built binaries work fine on Windows 10

  35. practicalswift commented at 11:09 am on June 6, 2021: contributor
    cr ACK b367745cfe19f6de3f44b3adc90fa08e36e44bb6: patch looks correct
  36. hebasto commented at 4:02 pm on June 17, 2021: member

    @laanwj @MarcoFalke @luke-jr

    Do you mind having another look at this PR?

  37. in src/fs.cpp:159 in b367745cfe
    153@@ -154,7 +154,10 @@ std::string get_filesystem_error_message(const fs::filesystem_error& e)
    154 #ifdef __GLIBCXX__
    155 
    156 // reference: https://github.com/gcc-mirror/gcc/blob/gcc-7_3_0-release/libstdc%2B%2B-v3/include/std/fstream#L270
    157-
    158+#if defined(__GNUC__) && !defined(__clang__)
    159+#pragma GCC diagnostic push
    160+#pragma GCC diagnostic ignored "-Wswitch"
    


    MarcoFalke commented at 8:41 am on June 23, 2021:
    Will this be needed after the boost::fs removal?

    hebasto commented at 9:19 am on June 23, 2021:
  38. laanwj commented at 6:20 am on August 27, 2021: member
    I’m not a big fan in general of pragmas or fixing warnings for the sake of fixing warnings but this seems minimal enough. Code review ACK b367745cfe19f6de3f44b3adc90fa08e36e44bb6
  39. laanwj merged this on Aug 27, 2021
  40. laanwj closed this on Aug 27, 2021

  41. hebasto deleted the branch on Aug 27, 2021
  42. sidhujag referenced this in commit 4fe76c802b on Aug 28, 2021
  43. DrahtBot locked this on Aug 27, 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-12-18 15:12 UTC

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