I created a default console application, and I changed the code on purpose to cause a L3 C4996 warning. The goal was to learn how to use the Treat Warnings as Errors and Treat Specific warnings as errors options. The results are not what I expect. The compiler reported C4996 as an error which I didn't expect since I had not changed the compiler options yet. Why is C4996 reported as an error when the /WX option is still set to no?
#include <iostream>
#include <cstring>
int main()
{
char message[20];
strcpy(message, "Hello World!\n"); // causes C4996
std::cout << message << std::endl;
}
Microsoft documentation for C4996 contains a subtle message that the /sdl option elevates C4996 to an error and /sdl is enabled in a default C++ console application project. This is why C4996 was shown as an error unexpectedly. I did not realize that the /sdl compiler switch existed and that it was enabled in the default settings of a native, console application project.