Skip to content

cmake: enable -Wall for MSVC when PICKY_COMPILER=ON #17050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Apr 14, 2025

Enable it for _MSC_VER <= 1943.

Omit it for not yet CI-tested MSVC versions, to avoid hitting unfixed
warnings emitted by future toolchain releases. It means we need
to explicitly opt-in to newer MSVC versions while fixing any new issues.

The newly enabled warnings did not reveal new issues. It hints that we
catch those with clang/gcc. Yet, these warnings may be useful for local
development done with MSVC.

Also:

  • disable and document warnings that don't seem useful, unactionable,
    or unfixable.
  • disable and document warnings found in Windows SDK headers.
  • tidy up a few comments, also to avoid
    -Wdocumentation-unknown-command, part of llvm/clang -Wall.
    lib\dynhds.h(159,29): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
    lib\ftp.c(337,15): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
    
    (This patch did not end up enabling -Wall for clang-cl.)

@vszakats vszakats added Windows Windows-specific CI Continuous Integration labels Apr 14, 2025
@vszakats vszakats marked this pull request as draft April 14, 2025 11:31
@vszakats vszakats changed the title appveyor: test warning priority msvc: test -Wall Apr 14, 2025
@testclutch

This comment was marked as outdated.

@vszakats vszakats changed the title msvc: test -Wall cmake: enable -Wall for MSVC when PICKY_COMPILER=ON Apr 14, 2025
@vszakats vszakats marked this pull request as ready for review April 14, 2025 23:39
@MarcelRaad
Copy link
Member

In my experience, keeping code /Wall clean only makes sense when supporting few compiler versions. Pretty much every new MSVC update breaks it, so I wouldn't use it for a public library. At least for C++, it might be less breaking for C.

which we may need to fix or opt-out from on upgrade

We can opt out our own CI, but we cannot do that for all our users. Might a CI job setting these flags manually be an alternative?

@vszakats
Copy link
Member Author

vszakats commented Apr 15, 2025

In my experience, keeping code /Wall clean only makes sense when supporting few compiler versions. Pretty much every new MSVC update breaks it, so I wouldn't use it for a public library. At least for C++, it might be less breaking for C.

which we may need to fix or opt-out from on upgrade

It's a downside, I agree.

We can opt out our own CI, but we cannot do that for all our users. Might a CI job setting these flags manually be an alternative?

It is, or, it's also an option to limit it to the latest CI-tested MSVC version
(VS2022) to avoid suprises on upgrade (or compiling this curl version in
the future with a then current MSVC.)

I'd prefer the latter, because this may rather help someone contributing
for curl using MSVC. In CI, it seems we already hit and fix these warnings
by finding them through gcc/clang.

Though the effect may be limited or perhaps overkill and nobody asked
for this. So, a 3rd option is to ditch this PR entirely.

@MarcelRaad
Copy link
Member

It is, or, it's also an option to limit it to the latest CI-tested MSVC version
(VS2022) to avoid suprises on upgrade (or compiling this curl version in
the future with a then current MSVC.)

Limiting this to a certain MSVC version makes sense to me too! Only keep in mind that new warnings come in minor versions, so we would need to use e.g. Visual Studio 2022 update 14 instead of just Visual Studio 2022.

@vszakats
Copy link
Member Author

Pushed a commit that draws the limit at MSVC_VERSION <= 1943.
Where 1943 is Visual Studio 2022 version 17.13 1, the version running
in GHA with windows 2022 runners.

What do you think?

Footnotes

  1. https://learn.microsoft.com/cpp/overview/compiler-versions?view=msvc-170

vszakats added a commit to vszakats/curl that referenced this pull request Apr 15, 2025
They did not find any new issue.

It might still be useful to enable it so that MSVC has a better change to
find issue we normally see with clang/gcc first.

Downside is that newer MSVC versions extend the `-Wall` warning list
with new ones, which we may need to fix or opt-out from on upgrade.

Also:
- disable and document warnings that don't seem useful, unactionable,
  or unfixable.
- disable and document warnings found in Windows SDK headers.
- silence a nit found by clang-cl with `-Wall` in comments.
  ```
  lib\dynhds.h(159,29): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
  ```
  (This patch did not end up enabling `-Wall` for clang-cl.)

Closes curl#17050
@@ -156,14 +156,14 @@ CURLcode Curl_dynhds_cadd(struct dynhds *dynhds,

/**
* Add a single header from an HTTP/1.1 formatted line at the end. Line
* may contain a delimiting \r\n or just \n. Any characters after
* may contain a delimiting CRLF or just LF. Any characters after
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would nominate this as one of the most stupid compiler warnings in recent days.

Does it perhaps also go away if the /** comment start is converted into a plain /* ?

Copy link
Member Author

@vszakats vszakats Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't the only one, it was catching email addresses in the copyright
header too, but curiously only a couple. It's not an MSVC warning, but an
llvm/clang one: -Wdocumentation-unknown-command.

The only reason I bothered fixing this one because other comments around
here prefer the CR/LF terminology. (Though the casing is still inconsistent.)

Yes, changing /** to /* also silences it. Weird.

lib/bufref.h:10:42: error: unknown command tag name [-Werror,-Wdocumentation-unknown-command]
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
                                         ^~~~~
In file included from lib/altsvc.c:32:
In file included from lib/vssh/../urldata.h:193:
lib/smb.h:10:36: error: unknown command tag name [-Werror,-Wdocumentation-unknown-command]
 * Copyright (C) Bill Nagel <wnagel@tycoint.com>, Exacq Technologies
                                   ^~~~~~~~
lib/ftp.c:337:15: error: unknown command tag name [-Werror,-Wdocumentation-unknown-command]
 * ending in '\r\n' and we prefer just '\n'.                  
              ^~                                              
lib/ftp.c:337:17: error: unknown command tag name [-Werror,-Wdocumentation-unknown-command]
 * ending in '\r\n' and we prefer just '\n'.                  
                ^~                                            
4 errors generated.                                                           

edit: silenced the ftp.c one too by dropping the *** decoration used
in that particular comment.

warning C4061: enumerator 'CURLUE_BAD_SCHEME' in switch of enum 'CURLUcode' is not explicitly handled by a case label
warning C4464: relative include path contains '..'
warning C4820: 'ossl_ctx': '2' bytes padding added after data member 'reused_session'
warning C4191: 'type cast': unsafe conversion from 'FARPROC' to 'void (__cdecl *)(void)'
warning C4711: function 'curl_dbg_malloc' selected for automatic inline expansion
memdebug.c(472,1): warning C5045: Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
lib\mprintf.c(998,34): warning C4774: 'snprintf' : format string expected in argument 3 is not a string literal
warning C4710: 'snprintf': function not inlined
vszakats added 16 commits April 16, 2025 11:21
lib/cshutdn.c(518): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/cshutdn.c(520): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/multi.c(1037): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/multi.c(1039): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/select.c(347): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/select.c(349): warning C4548: expression before comma has no effect; expected expression with side-effect
lib/select.c(351): warning C4548: expression before comma has no effect; expected expression with side-effect
C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\winuser.h(13979): warning C4255: 'GetThreadDpiAwarenessContext': no function prototype given: converting '()' to '(void)'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\winuser.h(14015): warning C4255: 'GetDpiForSystem': no function prototype given: converting '()' to '(void)'
C:\Program Files (x86)\Windows Kits\8.1\Include\um\winbase.h(8618): warning C4668: 'NTDDI_WIN7SP1' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' [C:\projects\curl\_bld\lib\libcurl_object.vcxproj]
C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(456): warning C4574: 'INCL_WINSOCK_API_TYPEDEFS' is defined to be '0': did you mean to use '#if INCL_WINSOCK_API_TYPEDEFS'? [C:\projects\curl\_bld\lib\libcurl_object.vcxproj]
cl : Command line warning D9014: invalid value '5045' for '/wd'; assuming '4999'
C:/projects/curl/lib/mprintf.c(995): warning C4619: #pragma warning : there is no warning number '4774' [C:\projects\curl\_bld\lib\libcurl_object.vcxproj]
seen with VS2022 ARM64:
```
lib\setopt.c(1582,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\setopt.c(1582,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\setopt.c(1595,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\setopt.c(1595,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\share.c(80,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\url.c(302,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\url.c(302,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
lib\share.c(241,1): warning C4746: volatile access of '<expression>' is subject to /volatile:<iso|ms> setting; consider using __iso_volatile_load/store intrinsic functions
```
```
lib\dynhds.h(159,29): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
```
@vszakats vszakats closed this in 8478365 Apr 16, 2025
@vszakats vszakats deleted the t-msvc-w branch April 16, 2025 12:34
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Enable it for `_MSC_VER <= 1943`.

Omit it for not yet CI-tested MSVC versions, to avoid hitting unfixed
warnings emitted by future toolchain releases. It means we need
to explicitly opt-in to newer MSVC versions while fixing any new issues.

The newly enabled warnings did not reveal new issues. It hints that we
catch those with clang/gcc. Yet, these warnings may be useful for local
development done with MSVC.

Also:
- disable and document warnings that don't seem useful, unactionable,
  or unfixable.
- disable and document warnings found in Windows SDK headers.
- tidy up a few comments, also to avoid
  `-Wdocumentation-unknown-command`, part of llvm/clang `-Wall`.
  ```
  lib\dynhds.h(159,29): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
  lib\ftp.c(337,15): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
  ```
  (This patch did not end up enabling `-Wall` for clang-cl.)

Closes curl#17050
nbaws pushed a commit to nbaws/curl that referenced this pull request Apr 26, 2025
Enable it for `_MSC_VER <= 1943`.

Omit it for not yet CI-tested MSVC versions, to avoid hitting unfixed
warnings emitted by future toolchain releases. It means we need
to explicitly opt-in to newer MSVC versions while fixing any new issues.

The newly enabled warnings did not reveal new issues. It hints that we
catch those with clang/gcc. Yet, these warnings may be useful for local
development done with MSVC.

Also:
- disable and document warnings that don't seem useful, unactionable,
  or unfixable.
- disable and document warnings found in Windows SDK headers.
- tidy up a few comments, also to avoid
  `-Wdocumentation-unknown-command`, part of llvm/clang `-Wall`.
  ```
  lib\dynhds.h(159,29): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
  lib\ftp.c(337,15): error : unknown command tag name [-Werror,-Wdocumentation-unknown-command]
  ```
  (This patch did not end up enabling `-Wall` for clang-cl.)

Closes curl#17050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build CI Continuous Integration cmake script Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

4 participants