build: Disable -Wbraced-scalar-init, which is incompatible with -Wc++11-narrowing #23191

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2110-buildW changing 1 files +2 −0
  1. MarcoFalke commented at 2:16 PM on October 5, 2021: member

    To test:

    void Fun(int) {}
    int main() {
        unsigned a(-1);
        Fun({a});
    }
    

    Before:

    $ clang++ -Wbraced-scalar-init -Wc++11-narrowing -std=c++17 /tmp/1.cpp -o /tmp/exe 
    /tmp/1.cpp:4:10: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'int' in initializer list [-Wc++11-narrowing]
        Fun({a});
             ^
    /tmp/1.cpp:4:10: note: insert an explicit cast to silence this issue
        Fun({a});
             ^
             static_cast<int>( )
    /tmp/1.cpp:4:9: warning: braces around scalar initializer [-Wbraced-scalar-init]
        Fun({a});
            ^~~
    1 warning and 1 error generated.
    

    After:

    $ clang++ -Wno-braced-scalar-init -Wc++11-narrowing -std=c++17 /tmp/1.cpp -o /tmp/exe 
    /tmp/1.cpp:4:10: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'int' in initializer list [-Wc++11-narrowing]
        Fun({a});
             ^
    /tmp/1.cpp:4:10: note: insert an explicit cast to silence this issue
        Fun({a});
             ^
             static_cast<int>( )
    1 error generated.
    
  2. build: Disable -Wbraced-scalar-init, which is incompatible with -Wc++11-narrowing fa2e12172b
  3. practicalswift commented at 2:21 PM on October 5, 2021: contributor

    Concept ACK

  4. vasild commented at 2:30 PM on October 5, 2021: member

    Why is it incompatible? In the output above there is 1 error due to Wc++11-narrowing and 1 warning due to Wbraced-scalar-init. When the latter is disabled the warning is not shown. I don't see the relation (incompatibility) between the two options.

    OTOH, F({a}) looks wrong, I would like the compiler to point it to me so that I can fix it to F(a), no?

  5. vasild commented at 2:42 PM on October 5, 2021: member

    Is the intention to use F({a}) with Wc++11-narrowing to get a warning for passing "incompatible" types? Could the same be achieved by F(a) with Wimplicit-int-conversion and/or Wsign-conversion?

  6. MarcoFalke commented at 2:43 PM on October 5, 2021: member

    OTOH, F({a}) looks wrong, I would like the compiler to point it to me so that I can fix it to F(a), no?

    F(a) will disable -Wc++11-narrowing.

  7. DrahtBot added the label Build system on Oct 5, 2021
  8. MarcoFalke commented at 3:22 PM on October 5, 2021: member

    Could the same be achieved by F(a) with Wimplicit-int-conversion and/or Wsign-conversion?

    It is currently not possible to compile Bitcoin Core with either of those settings.

  9. DrahtBot commented at 11:48 AM on October 6, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23269 (build: remove redundant warning flags 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.

  10. DrahtBot added the label Needs rebase on Oct 14, 2021
  11. DrahtBot commented at 2:47 PM on October 14, 2021: member

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  12. in configure.ac:479 in fa2e12172b
     474 | @@ -475,6 +475,8 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
     475 |    AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
     476 |    AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
     477 |    AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
     478 | +  dnl -Wbraced-scalar-init is incompatible with -Wc++11-narrowing
     479 | +  AX_CHECK_COMPILE_FLAG([-Wbraced-scalar-init],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-braced-scalar-init"],,[[$CXXFLAG_WERROR]])
    


    fanquake commented at 3:02 AM on November 16, 2021:
      AX_CHECK_COMPILE_FLAG([-Wbraced-scalar-init], [NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-braced-scalar-init"], [], [$CXXFLAG_WERROR])
    
  13. MarcoFalke closed this on Nov 17, 2021

  14. MarcoFalke deleted the branch on Nov 17, 2021
  15. DrahtBot locked this on Nov 17, 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 06:14 UTC

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