4 ms·
int x; int y = square(x); // Passing a garbage value at runtime. My C++ compiler doesn’t build that: error C4700: uninitialized local variable 'x' use
by Const-me 8y ago
int x;
int y = square(x);
// Passing a garbage value at runtime.
My C++ compiler doesn’t build that:
error C4700: uninitialized local variable 'x' used
- int_19h 8y agoThat's because you're compiling with warnings-as-errors. And even then it's still unable to detect anything but the simplest case. E.g. this compiles with no warnings: void foo(int& x) {} int x; foo(x); int y = square(x);
- Const-me 8y ago> you're compiling with warnings-as-errors. I'm not. The compiler is VC++ with default project settings. "Treat warnings as errors" setting is set to "No (/WX-)" By default, VC++ compiler turns on this for new C++ projects: https://docs.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=vs-2019 https://docs.microsoft.com/en-us/cpp/build/reference/sdl-ena... That's why it fails to build.
- int_19h 8y agoC4700 is a warning per VC++ docs: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-and-level-4-c4700 https://docs.microsoft.com/en-us/cpp/error-messages/compiler... So by definition, if it's reported as an error, you're compiling with warnings-as-errors enabled, at least with respect to that one warning. The default project settings you refer to are Visual Studio defaults (for new projects created from a template), not VC++ defaults. If you invoke cl.exe directly from command line on your code, you'll see C4700 being reported as a warning, but it still produces the binary. /WX is a switch to treat all warnings as errors, but it's not the only switch that controls warnings-as-errors behavior - you have all the other /W... switches, from level-based approach to setting it for specific warnings. And /sdl is (in addition to all the other things it does) an alias for a bunch of those switches. Indeed, on the very page you linked to, it literally says: "/sdl enables these warnings as errors ... C4700". And you can even override that by doing something like /sdl /wd4700.