This piece of code (pay attention to the commented line):
#include <malloc.h> #pragma warning(error: 4701) int main(){ char buffer[1024]; //buffer[0] = 0; void *p; int size = 1; if (size < 2) p = malloc(size); free(p); // C4701 return 0; }
Gives the following warning (as expected):
f:\d\warning.cpp(13) : error C4701: potentially uninitialized local variable 'p' used
However , when I uncomment the assignment in main() , the warning is no longer indicated. I am compiling with the /RTC1 command line /RTC1 to enable runtime error checking :
cl.exe /RTC1 warning.cpp
I tried the latest 64-bit versions of compilers from Visual C ++ 2013 and 2015. Both of them produce the same behavior.
Question: is this a compiler error, or is there an explanation for this? The Microsoft documentation mentions that / RTC 1 may give a runtime error in places where C4701 is specified, but it does not say anything about suppressing the warning.
EDIT: The incomprehensible part is that the warning disappears only when buffer[0] = 0; does not comment.
c ++ visual-c ++ compiler-bug cl
Georgy pashkov
source share