最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Why is C4996 treated as error when WX is off? - Stack Overflow

programmeradmin0浏览0评论

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;
}

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;
}
Share Improve this question edited Feb 7 at 23:42 shawn1874 asked Feb 6 at 19:19 shawn1874shawn1874 1,4511 gold badge13 silver badges29 bronze badges 4
  • Do you have /sdl enabled? – Eljay Commented Feb 6 at 19:35
  • 3 You seem to build some other configuration or platform, because it's showing "Debug", otherwise it would be showing "Debug (Active)". – 3CxEZiVlQ Commented Feb 6 at 19:45
  • Yes that was it Eljay. I've never heard of that option before. Most of the visual studio projects I've had to deal with were created years ago so I'd never seen that enabled before. I can make that into an answer or you can if you want to get the credit for an answer. – shawn1874 Commented Feb 6 at 19:45
  • Hi ,Glad to know you've found the solution to resolve this issue! See can I answer my own question, Just a reminder :) – Minxin Yu - MSFT Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 2

Microsoft documentation for C4996 contains a subtle message that the /sdl option elevates C4996 to an error and /sdl is enabled in a default console application project.

发布评论

评论列表(0)

  1. 暂无评论