Pushback on vector fails - VS 2017

2019-06-25 17:26发布

问题:

In Visual Studio 2017 Professional I created a new Empty Visual C++ Project and then added a new C++ File. After inserting this code

#include <vector>

int main()
{
    std::vector<bool> args_convert;
    args_convert.push_back(false);
    return 0;
}

and trying to compile it I get this error:

1>------ Build started: Project: DummyProject3, Configuration: Debug Win32 ------
1>Source.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): error C2446: '<': no conversion from 'unsigned int' to 'unsigned int *'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2325): note: while compiling class template member function 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(int)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2545): note: see reference to function template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(int)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2490): note: see reference to class template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3094): note: see reference to class template instantiation 'std::_Vb_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3093): note: while compiling class template member function 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)'
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\a_working_files\coding\visual_studio\dummyproject3\dummyproject3\source.cpp(6): note: see reference to function template instantiation 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)' being compiled
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\a_working_files\coding\visual_studio\dummyproject3\dummyproject3\source.cpp(5): note: see reference to class template instantiation 'std::vector<bool,std::allocator<_Ty>>' being compiled
1>        with
1>        [
1>            _Ty=bool
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>Done building project "DummyProject3.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

In this online compiler http://cpp.sh/74rxa the sample code works without issues.

In particular, when I change Configuration Properties --> General -> Platform Toolset from v141 to an earlier version (such as v140) it works. What has changed in v141? My VS version is 15.7.2