Home Dashboard Directory Help

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



Sign in
to vote
Type: Bug
ID: 789970
Opened: 6/12/2013 3:08:59 AM
Access Restriction: Public
User(s) can reproduce this bug


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

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)
Sign in to post a workaround.
Posted by Frank Heimes on 6/12/2013 at 3:34 AM
Place a file named "afxwin.h" at a location where it is included first according to your include path.

-- afxwin.h -------------------------------------------------------------
#pragma once

#ifndef __AFXWIN_H__
    #include <..\..\atlmfc\include\afxwin.h>

    #ifndef DEBUG
        #pragma warning(pop)
        #pragma warning(pop)
File Name Submitted By Submitted On File Size  
TestAfxWin.zip (restricted) 6/12/2013 -
UploadSummary-130612100859.xml (restricted) 6/12/2013 -
VsInfo.xml (restricted) 6/12/2013 -
DxDiagOutput.txt (restricted) 6/12/2013 -
SolutionFingerprint.10088.html (restricted) 6/12/2013 -
SolutionFingerprint.1520.html (restricted) 6/12/2013 -