在 VS2012 中包含 afxwin.h 时,使用#pragma warning(pop) 恢复警告状态在发布(非调试)时失败

Restoring warning state with #pragma warning(pop) fails in release (not debug) when including afxwin.h in VS2012

我将项目的警告级别设置为 4,并意识到 #pragma warning(pop) 在包含 afxwin.h

时似乎在发布版本中失败

这里是复制代码:

#pragma warning(push, 4)

void boo1()
{
    auto x = 43;

}

#pragma warning(push)

#define _AFXDLL
#include <afxwin.h>

#pragma warning(pop)

void boo2()
{
    auto x = 43;

}

在调试中我收到两条消息

warning C4189: 'x' : local variable is initialized but not referenced

每个 boo 函数一个。 如果我切换到发布,我怎么会只有一个,第一个。

#include <afxwin.h>

行为怪异,我想知道发生了什么。似乎 VS 2013 没有这种行为,除非我将 VS2013 解决方案重新定位为使用 v110 Visual Studio 2012 平台工具集。

我是否发现了一个模糊的编译器错误?

快速 google 搜索显示此问题 reported 于 visual studio 2012 年解决,并于 2013 年修复。报价单:

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.