News for hackers. Stuff that matters.
Re:Rust – Compile Time Memory Safety by Const-me on Tuesday April 23, 2019 @08:54AM (#19728083)

    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

Re:Rust – Compile Time Memory Safety by int_19h on Tuesday April 23, 2019 @04:26PM (#19732478)
That'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);
Re:Rust – Compile Time Memory Safety by Const-me on Tuesday April 23, 2019 @04:52PM (#19732726)
> 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-ena... That's why it fails to build.

Re:Rust – Compile Time Memory Safety by int_19h on Tuesday April 23, 2019 @07:00PM (#19733854)
C4700 is a warning per VC++ docs:

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.