godot: Evaluation of warnings raised by VS 2019 with `/W4`

Godot version

4.0.beta (14e1f36e614686f3fea0c74fac3624d1027dd5cc)

System information

Windows 10 64-bit, VS 2019, MSVC 14.29.30133

Issue description

I made some fixes and Godot’s master branch should now build without warnings when using /W3 with VS 2019 (at least tools=yes target=debug build, optimized builds might find other unfixed warnings with /W3). It’s worth noting that our warnings=all preset which sets /W3 also disables /wd4267 /wd4244 /wd4305 /wd4018 /wd4800 as non-essential warnings.

I gave a try at using /W4 without disable the above non-essential warnings, here are the results:

369,102 warnings raised.

Oh boy.

Let’s categorize them and see which ones are worth investigating/fixing and which ones should be ignored (or if we should outright give up on /W4 if it doesn’t catch any useful warning compared to /W3).

Here’s the list of unique warning codes raised and the number of occurrences for each:

Code Occurrences Warning Level Message Comment
C4100 220,816 4 ‘identifier’: unreferenced formal parameter Doesn’t play nice with polymorphism, should be ignored. Silenced by #66595
C4127 966 4 conditional expression is constant Fixed partially by #66583
C4201 8,487 4 nonstandard extension used: nameless struct/union Only relevant for C89 compat, we should ignore it. Silenced by #66595
C4244 51,640 2 and 3/4 ‘conversion’ conversion from ‘type1’ to ‘type2’, possible loss of data Ignored in warnings={all,moderate}
C4245 352 4 ‘conversion’ : conversion from ‘type1’ to ‘type2’, signed/unsigned mismatch Silenced by #66595
C4267 1203 3 ‘var’ : conversion from ‘size_t’ to ‘type’, possible loss of data Ignored in warnings={all,moderate}
C4305 18,164 1 ‘context’ : truncation from ‘type1’ to ‘type2’ Ignored in warnings={all,moderate}
C4324 12 4 ‘struct_name’ : structure was padded due to __declspec(align()) Silenced in #66545
C4389 2 4 ‘equality-operator’ : signed/unsigned mismatch Fixed by #66545
C4456 3 4 declaration of ‘identifier’ hides previous local declaration Fixed by #66545
C4458 67,374 4 declaration of ‘identifier’ hides class member 66,047 occurrences fixed by #66539, 1,330 remain
C4459 1 4 declaration of ‘identifier’ hides global declaration Fixed by #66545
C4701 17 4 Potentially uninitialized local variable ‘name’ used Fixed by #66544 and #66548
C4702 26 4 unreachable code Fixed by #66543 and #66568
C4703 2 4 Potentially uninitialized local pointer variable ‘name’ used Fixed by #66548
C4706 37 4 assignment within conditional expression Fixed by #66542 and #66545

For each of the above, we should assess some of the situations in which the warnings are raised and see if they’re worth fixing. The warnings emitted tens of thousands of time typically come from core templates and get re-emitted everytime the template is used.

I’ll post some details on each warning in follow-up comments.

Here’s the full build log (7z compressed and then zipped so it can be attached, unzipped it’s 59MB):

build-W4.log.7z.zip

Edit: Edited log with Unix line endings, attempting to fix some of the scrambled lines where multiple warnings would be listed on the same line, or paths would get truncated:

build-W4-unix.log.7z.zip

Some remarks:

  • Looks like C4018 which we ignore with warnings=all is not emitted with a plain /W4 run. Might be that we fixed it and we can stop ignoring it.
  • Similarly, C4800 which we ignore is not emitted. According to the docs it has a different meaning in VS <= 2015 and VS >= 2019 and is not emitted in VS 2017. We only support VS >= 2017 so we could un-ignore it too.

Steps to reproduce

  • VS 2019, MSVC 14.29.30133
  • scons p=windows CCFLAGS="/W4"

Minimal reproduction project

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I still get this error in Godot 4.2:

core\templates\cowdata.h(138) : error C2220: the following warning is treated as an error
core\templates\cowdata.h(138) : warning C4723: potential divide by 0

When compiling on Windows with this command:

scons p=windows target=editor warnings=all werror=yes -j4

Checked warnings in the TextServers as a most familiar part of code:

Warnings from the headers seems to be repeated multiple times, so the real number is much smaller.

  • A bunch of C4100, unused function arguments in the virtual / dummy methods, I guess we can ignore it.
  • BitField internally use uint32_t but VARIANT_BITFIELD_CAST is using int64_t (probably BitField should be changed to be 64-but like most of the ints and for better compatibility with GDExtension and Variant).
  • script_instance is declared in Object and inside wrappers generated by GDVIRTUAL*, should not cause any bugs, but probably should be renamed in the binding generator.
  • A bunch of possible loss of data warnings, I’m not sure what to do with them, it’s pretty much inevitable when int64_t is used, and adding casts to every case seems like an overkill to me.