Unpaired pragma warning push/pop in afxwin.h in Release build - by Frank Heimes

Status : 

 


1
0
Sign in
to vote
ID 789970 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 6/12/2013 3:08:59 AM
Access Restriction Public

Description

Compile the following code in RELEASE build (use attached sample project):

---------------------------------------
#include <SDKDDKVer.h>
#include <codeanalysis\warnings.h>

#pragma warning(push)
#pragma warning(disable : ALL_CODE_ANALYSIS_WARNINGS)
#include <afxwin.h>
//#pragma warning(pop) // (C) <<< Uncomment these lines to cure the problem
//#pragma warning(pop) // (C) <<< Uncomment these lines to cure the problem
#pragma warning(pop)

int _tmain(int argc, _TCHAR* argv[])
{
    int i = 0;
    {
        int i = 0; // (A) expected this warning: 
    }
#pragma warning (default: 6246)
    int j = 0;
    {
        int j = 0; // (B) OK warning works: 
    }
    return 0;
}
---------------------------------------

Line (A) is suppossed to trigger warning: 
warning C6246: Local declaration of 'i' hides declaration of the same name in outer scope.
but it does not.

Line (B) correctly triggers warning:
warning C6246: Local declaration of 'j' hides declaration of the same name in outer scope.

Uncommenting the two lines (C) fixes the problem.
We found a very likely cause of this problem in afxwin2.inl, lines 784 - 791:

#pragma warning(push)
#pragma warning(disable: 6001 6054)
_AFXWIN_INLINE int CListBox::GetText(_In_ int nIndex, _Pre_notnull_ _Post_z_ LPTSTR lpszBuffer) const
{ 
 ASSERT(::IsWindow(m_hWnd)); 
 return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer); 
}
#pragma warning(push)

The second push pragma on line 791 must be a pop statement instead.
A classic copy-and-paste - and worse - careless mistake.

Since you recently fixed a very similar error, we are quite disappointed about this bug.
See http://connect.microsoft.com/VisualStudio/feedback/details/660707/c-code-analyzer-pragma-warning-pop-does-not-restore-the-state-before-paragma-push-in-all-cases
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:21 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 6/18/2013 at 10:48 AM
Hello,

Thanks for the report. This has been fixed in MFC for Visual Studio 2013 RTM.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 6/12/2013 at 8:34 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 6/12/2013 at 3:51 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)