4

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:

enter image description here

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

Phil-ZXX
  • 2,359
  • 2
  • 28
  • 40
  • might be unrelated to your problem, but note that `std::vector` can be considered broken, because it is not really a `std::vector` – 463035818_is_not_an_ai Jun 12 '18 at 11:58
  • `std::vector` is... special. It's implemented as a bit sequence, which was supposed to conserve space. A design failure, which can't be removed from strandard to retain backward compatibility. Best to avoid. – Yksisarvinen Jun 12 '18 at 11:58
  • 3
    That is weird, because it works on an [online MSVC 2015](https://godbolt.org/g/Y5Bv68) and [MSVC 2017](https://godbolt.org/g/9rbBZv) – Rakete1111 Jun 12 '18 at 11:59
  • 1
    I can compile this on `VS 2017` with `platform toolset 141`. Try to retarget your solution. – Gaurav Sehgal Jun 12 '18 at 12:07
  • What update of 2017? (Help about should tell you). – Yakk - Adam Nevraumont Jun 12 '18 at 12:09
  • @Yksisarvinen: Avoiding it doesn't solve the problem. It's a reasonable enough class. The real problem is that it breaks generic code which tries to instantiate a container `std::vector` for the case where `T==bool`. This forces the generic code to specialize for `T==bool`. This happened because generic code wasn't as well-understood in 1998 as it is today. – MSalters Jun 12 '18 at 12:10
  • 1
    @Yakk-AdamNevraumont Current Version = 15.7.2 – Phil-ZXX Jun 12 '18 at 12:13
  • v140 is the compiler from VS2015. Since then [just about *everything* has changed](https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes#whats-new-in-157). – Bo Persson Jun 12 '18 at 13:01

0 Answers0