Home Dashboard Directory Help
Search

A false C4701 bothers me under a certain condition. by WAAN26


Status: 

Closed
 as Fixed Help for as Fixed


6
2
Sign in
to vote
Type: Bug
ID: 587106
Opened: 8/17/2010 10:53:05 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

in c++ project, when the project's warning level is 4. and build configuration is 'Release'.

- a false "warning C4701: potentially uninitialized local variable 'var' used" is reported.
- or if that warning is true, in 'Debug' build config, it did not appears.

please see the 'Steps to reproduce'.
Details
Sign in to post a comment.
Posted by Microsoft on 11/12/2010 at 4:33 PM
I was trying to post the workaround to the workarounds page but it put it on the comments anyway.

I've reproduced the warning here, and verified that it's fixed in the next release. In the mean time, please use one of the workarounds.

We continually work to improve the quality of our warnings and eliminate false-positives, but some do still exist, and our policy is to make such warnings off-by-default but not to disable them entirely since they still have value for some customers. 4701 is a level 4 warning, and since the default warning level is 3, all level 4 warnings are off by default, and may produce false positives in cases we haven't yet fixed.


Posted by Microsoft on 11/12/2010 at 4:25 PM
Various workarounds are:

a) Don't use /W4
b) Don't use /WX while using /W4 and ignore the warning
c) Disable the warning for places you know it to be incorrect, using:

#pragma warning( push )
#pragma warning( disable : 4701 )
// line of code generating the warning goes here
#pragma warning( pop )
Posted by WAAN26 on 8/31/2010 at 1:09 AM
Please, check this out.

http://cid-c8cb4e6f4f6fafe1.office.live.com/self.aspx/Public/Hi%20Jerry%20Goodwin.zip
Posted by Microsoft on 8/30/2010 at 1:58 PM
Hi, for some reason your repro steps came through as one long line without line breaks, and the code part of the repro steps got truncated.

Please reply with your little sample program again, and hopefully it won't all show up on one line this time.

However, without looking at your specific case, I can answer that the compiler's behavior is most likely by design. We have two messages for uninitialized variable use: C4700 and C4701. Because of the limitations of compiler analysis, there are some easy situations where we can prove that a variable is being used without being initialized, and for those we issue C4700. But there are many more where the program flow is too complex for us to absolutely determine whether a variable will definitely be used while still uninitialized, but where we can determine that there is at least one code path -- which might or might not be executed in practice -- that would result in an uninitialized variable use. We use C4701 for these cases where we can't prove an error exists. We want to let users have a way to find out when they might have an error, but we put the warning on level 4 because it does give false positives.

That said, if you can submit your repro (again) and we can figure out a way to improve the accuracy of the message for your case, we certainly want to consider it. I gather from the part of the example I can see that it has something to do with arrays, and that's a particularly tricky area so we'd like to see the example to make sure there's no bug in our analysis heuristics.

Jerry Goodwin
VS C++ Codegen & Tools
Posted by Microsoft on 8/18/2010 at 2:39 AM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by Microsoft on 8/18/2010 at 2:37 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
Hi Jerry Goodwin.zip 8/31/2010 4 KB
Hi Jerry Goodwin.zip 8/31/2010 4 KB
Hi Jerry Goodwin.zip 8/31/2010 4 KB