警告 C4350 は、「非 const 参照は左辺値にのみバインドできます」と言います。C4350 はデフォルトでオフになっているため、あまり詳しくはわかっていません。私はこの投稿を読みましたが、それは理にかなっています: 非定数参照は左辺値にのみバインドされる可能性があります
とにかく、VS2008 VC++ プロジェクトを VS2012 に更新しようとしているので、それについて質問しています。私がそうすると、何百ものC4350警告が表示されますが、これは何らかのレガシーな理由でオンにしました(確かに再評価する必要があるかもしれません)。警告を再現できるこの単純なコードに絞り込みましたが、プリコンパイル済みヘッダーがオフになっている場合のみです。
#pragma warning(default:4350)
#include "stdafx.h"
#include <string>
int _tmain(int argc, char* argv[])
{
return 0;
}
プリコンパイル済みヘッダーをオンにしても、警告は表示されません。また、VS2008でも発生しません。
これは std:string の Visual Studio 2012 のバグですか? プリコンパイル済みヘッダーによって動作が変わるのはなぜですか? 警告を無視するのではなく、どうすれば問題を解決できますか? ありがとう!
警告は次のとおりです(フォーマットが不十分で申し訳ありません。私が理解できる最善のものでした):
c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(689): 警告 C4350: 動作の変更: 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc(const std::_Wrap_alloc<_Alloc> & ) 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc>(_Other &) throw()' の代わりに呼び出される throw()'
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(838) : 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc' の宣言を参照してください
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(850) : 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc' の宣言を参照してください
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> 非 const 参照は左辺値にのみバインドできます
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(688) : クラス テンプレート メンバー関数のコンパイル中 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>:: _Getal(void) const'
1>と
1> [
1> _Alloc=std::アロケータ、
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(898) : 関数テンプレートのインスタンス化への参照を参照してください 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>:: _Getal(void) const' コンパイル中
1>と
1> [
1> _Alloc=std::アロケータ、
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(700) : コンパイル中のクラス テンプレートのインスタンス化 'std::_String_alloc<_Al_has_storage,_Alloc_types>' への参照を参照してください
1>と
1> [
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\stdexcept(31) : コンパイル中のクラス テンプレートのインスタンス化 'std::basic_string<_Elem,_Traits,_Alloc>' への参照を参照してください
1>と
1> [
1> _Elem=文字、
1> _Traits=std::char_traits,
1> _Alloc=std::アロケータ
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(689): 警告 C4350: 動作の変更: 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc(const std::_Wrap_alloc<_Alloc > 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc>(_Other &) throw()' の代わりに &) throw()' が呼び出されました
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(838) : 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc' の宣言を参照してください
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(850) : 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc' の宣言を参照してください
1>と
1> [
1> _Alloc=std::アロケータ
1> ]
1> 非 const 参照は左辺値にのみバインドできます
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(688) : クラス テンプレート メンバー関数のコンパイル中 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>:: _Getal(void) const'
1>と
1> [
1> _Alloc=std::アロケータ、
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(898) : 関数テンプレートのインスタンス化への参照を参照してください 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>:: _Getal(void) const' コンパイル中
1>と
1> [
1> _Alloc=std::アロケータ、
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(700) : コンパイル中のクラス テンプレートのインスタンス化 'std::_String_alloc<_Al_has_storage,_Alloc_types>' への参照を参照してください
1>と
1> [
1> _Al_has_storage=false,
1> _Alloc_types=std::_String_base_types>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(689) : コンパイル中のクラス テンプレートのインスタンス化 'std::basic_string<_Elem,_Traits,_Alloc>' への参照を参照してください
1>と
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits,
1> _Alloc=std::アロケータ
1> ]