2012-10-18 27 views
3

警告C4350說:「一個非const引用只能綁定到一個左值」。我想因爲C4350默認關閉,所以我沒有在那裏發現很多東西。我讀過這篇文章,它是有道理的: Non-const reference may only be bound to an lvalue「警告C4350:行爲改變」,包括<string>並且沒有預編譯頭文件

無論如何,我在問這個問題,因爲我試圖將VS2008 VC++項目更新到VS2012。當我這樣做時,我得到了數百個C4350警告,這些警告是由於一些遺留原因而導致的(這可能需要重新評估)。我已經縮短到的代碼,可以重現警告這個簡單一點,但只有當我已經預編譯頭關閉:

#pragma warning(default:4350) 

#include "stdafx.h" 
#include <string> 

int _tmain(int argc, char* argv[]) 
{ 
    return 0; 
} 

如果我把precomiled頭對我沒有得到任何警告。我也無法讓它在VS2008中發生。

這是在std:string中的Visual Studio 2012錯誤嗎?爲什麼預編譯頭改變了行爲?我如何解決這個問題,而不是忽略警告?謝謝!

的警告(爲窮人格式化對不起,這是我能想出的最好):

C:\ Program Files文件(x86)的\微軟的Visual Studio 11.0 \ VC \包括\ xstring(689):警告C4350:行爲改變: '的std :: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc(常量的std :: _ Wrap_alloc < _Alloc> &)擲()' 調用,而不是「的std :: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc>(_其他& )throw()'

1> with

1> [

1> _Alloc =標準::分配器

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xmemory0(838):看到聲明的 '標準:: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc'

1>使用

1> [

1> _Alloc =標準::分配器

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xmemory0(850):見「STD聲明:: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc '

1>使用

1> [

1> _Alloc =標準::分配器

1>]

1>非const引用可能只綁定到一個左值

1> c:\ program files(x86)\ microsoft visual studio 11。0 \ VC \包括\ xstring(688):在編譯類模板的成員函數 '的std :: _ Wrap_alloc < _Alloc>的std :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types> :: _ Getal(無效)常量'

1>使用

1> [

1> _Alloc =標準::分配器,

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ St​​ring_base_types>

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xstring(898):見參考起作用模板實例「的std :: _ Wrap_alloc < _Alloc> STD :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types> :: _ Getal(無效)常量」被編譯

1>使用

1> [

1> _Alloc =標準::分配器,

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ St​​ring_base_types>

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xstring(700):見參考文獻類模板實例 '的std :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types>' 被編譯

1>使用

1> [

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ St​​ring_base_types>

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ stdexcept(31):見參考文獻類模板實例 '的std :: basic_string的< _Elem,_Traits,_Alloc>' 被編譯

1>使用

1> [

1> _Elem =炭,

1> _Traits =標準:: char_traits,

1> _Alloc =標準::分配器

1>]

1> C^:\ program files(x86)\ microsoft visual studio 11。0 \ vc \ include \ xstring(689):warning C4350:behavior change:'std :: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc(const std :: _ Wrap_alloc < _Alloc> &)throw()'called'std :: _Wrap_alloc < _Alloc> :: _ Wrap_alloc>(_其他&)擲()」

1>使用

1> [

1> _Alloc =標準::分配器

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xmemory0(838):見的聲明 '的std :: _ Wrap_alloc < _Alloc> :: _ Wrap_alloc'

1>使用

1> [

1> _Alloc =標準::分配器

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xmemory0( 850):參見'std :: _ Wrap_alloc <的聲明_Alloc> :: _ Wrap_alloc」

1>使用

1> [

1> _Alloc =標準::分配器

1>]

1>一種非const引用只能綁定一個左值

1> c:\ program files(x86)\ microsoft visual studio 11.0 \ vc \ include \ xstring(688):編譯類模板成員函數'std :: _Wrap_alloc < _Alloc>的std :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types> :: _ Getal(無效)常量」

1>使用

1> [

1> _Alloc =標準::分配器,

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ St​​ring_base_types>

1>]

1> c:\ program files(x86)\ microsoft visual studio 11。0 \ VC \包括\ xstring(898):見參考起作用模板實例 '的std :: _ Wrap_alloc < _Alloc>的std :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types> :: _ Getal(無效)常量' 被編譯

1>與

1> [

1> _Alloc =標準::分配器,

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ St​​ring_base_types>

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\ xstring(700):見參考文獻類模板實例「的std :: _ St​​ring_alloc < _Al_has_storage,_Alloc_types >」被編譯

1>使用

1> [

1> _Al_has_storage =假,

1> _Alloc_types =標準:: _ String_base_types>

1>]

1> C:\程序文件(86)\微軟的Visual Studio 11.0 \ VC \包括\串(689):見參考文獻類模板實例「的std :: basic_string的< _Elem,_Traits,_Alloc>」被編譯

1>使用

1> [

1> _Elem = wchar_t的,

1> _Traits =標準:: char_traits,

1> _Alloc =標準::分配器

1>]

回答

3

微軟回答我的問題在這裏:

http://connect.microsoft.com/VisualStudio/feedback/details/767960/warning-c4350-behavior-change-when-including-string-and-no-precompiled-header

摘要:

這是一個Visual Studio 2012錯誤在s TD:字符串? 如果要是乾淨建立在警告級別4,排除此警告

爲什麼預編譯頭更改的行爲 - 他們不指望它作爲一個bug? - 編譯器會忽略預編譯頭之前的所有內容,在這種情況下,這是我啓用警告的編譯指示語句。在屬性設置中啓用預編譯頭文件會導致忽略編譯指示。誰知道?

如何解決問題,而不是忽略警告? - 沒有修復它看起來,只是忽略警告