Warning C4350 says "A non-const reference may only be bound to an lvalue". I think since C4350 is off by default I haven't found much out there on it. I have read this post and it makes sense: Non-const reference may only be bound to an lvalue
Anyway, I'm asking about it because I'm trying to update VS2008 VC++ projects to VS2012. When I do I get hundreds of C4350 warnings which I have turned on for some legacy reason (that admittedly may need to be reassessed). I have whittled it down to this simple bit of code that can reproduce the warning, but only if I have precompiled headers turned off:
#pragma warning(default:4350)
#include "stdafx.h"
#include <string>
int _tmain(int argc, char* argv[])
{
return 0;
}
If I turn precomiled headers on I get no warning. I also can't get it to happen in VS2008.
Is this a Visual Studio 2012 bug in std:string? Why does the precompiled header change the behavior? How do I fix the problem, as opposed to just ignoring the warning? Thanks!
The warning is (sorry for the poor formatting, it was the best I could figure):
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 instead of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc>(_Other &) throw()'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(838) : see declaration of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(850) : see declaration of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> A non-const reference may only be bound to an lvalue
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(688) : while compiling class template member function 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>::_Getal(void) const'
1> with
1> [
1> _Alloc=std::allocator,
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) : see reference to function template instantiation 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>::_Getal(void) const' being compiled
1> with
1> [
1> _Alloc=std::allocator,
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) : see reference to class template instantiation 'std::_String_alloc<_Al_has_storage,_Alloc_types>' being compiled
1> with
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) : see reference to class template instantiation 'std::basic_string<_Elem,_Traits,_Alloc>' being compiled
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits,
1> _Alloc=std::allocator
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 instead of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc>(_Other &) throw()'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(838) : see declaration of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(850) : see declaration of 'std::_Wrap_alloc<_Alloc>::_Wrap_alloc'
1> with
1> [
1> _Alloc=std::allocator
1> ]
1> A non-const reference may only be bound to an lvalue
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(688) : while compiling class template member function 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>::_Getal(void) const'
1> with
1> [
1> _Alloc=std::allocator,
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) : see reference to function template instantiation 'std::_Wrap_alloc<_Alloc> std::_String_alloc<_Al_has_storage,_Alloc_types>::_Getal(void) const' being compiled
1> with
1> [
1> _Alloc=std::allocator,
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) : see reference to class template instantiation 'std::_String_alloc<_Al_has_storage,_Alloc_types>' being compiled
1> with
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) : see reference to class template instantiation 'std::basic_string<_Elem,_Traits,_Alloc>' being compiled
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits,
1> _Alloc=std::allocator
1> ]