boost 1.73 messages reporting during project build - c++

I'm using Boost 1.73 on a older project which was using Boost 1.48. My intention is to fix any warnings and errors along the way.
When compiling the project I'm getting some odd messages which are not in the source of the project but in boost itself, these messages are like most error messages, cryptic and not terribly helpful.
1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1> with
1> [
1> _Ty=int
1> ]
1> and
1> [
1> _Ty2=unsigned short
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1> with
1> [
1> date_type=boost::gregorian::date
1> ]
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(54): note: see reference to class template instantiation 'boost::arg<9>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(53): note: see reference to class template instantiation 'boost::arg<8>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(52): note: see reference to class template instantiation 'boost::arg<7>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(51): note: see reference to class template instantiation 'boost::arg<6>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(50): note: see reference to class template instantiation 'boost::arg<5>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(49): note: see reference to class template instantiation 'boost::arg<4>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(48): note: see reference to class template instantiation 'boost::arg<3>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(47): note: see reference to class template instantiation 'boost::arg<2>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(46): note: see reference to class template instantiation 'boost::arg<1>' being compiled
Is there anything I can do?
I'm using MSVC 2017.
I've narrowed the problem down to just one file and commented out everything except:
#include <boost/date_time.hpp>
This is what I get when compiling just this:
1>------ Build started: Project: Debug Service Group, Configuration: Debug Win32 ------
1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1> with
1> [
1> _Ty=int
1> ]
1> and
1> [
1> _Ty2=unsigned short
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1> with
1> [
1> date_type=boost::gregorian::date
1> ]
1>Done building project "Debug Service Group.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The warnings are harmless. Here's the source in boost\date_time\date_parsing.hpp line 99
static std::map<std::string, unsigned short> month_map =
{ { "jan", 1 }, { "january", 1 },
As you can see the value type of the map is unsigned short but it is being initialised with int values.
I'm slightly surprised at the warning, you might think that MSVC 2017 would be smart enough to realise that assigning 1 to an unsigned short is not a problem.
I don't get any warnings with MSVC 2019

Related

I tried to use boost however it got a bunch of errors when I compile the code

I tried to use boost library with the code below, but it got a bunch of error when I tried to compile it
#include <string>
#include <sstream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
std::string base64_decode(const std::string&);
std::string base64_encode(const unsigned char*, size_t);
using std::string;
void zipstr(string uncompressedstr, string & compressedstr)
{
std::stringstream compressed;
std::stringstream original;
original << uncompressedstr;
boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
out.push(boost::iostreams::zlib_compressor());
out.push(original);
boost::iostreams::copy(out, compressed);
/**need to encode here **/
compressedstr = base64_encode(reinterpret_cast<const unsigned char*>(compressed.str().c_str()), compressed.str().length());
}
void unzipstr(string compressedstr, string &uncompressedstr)
{
std::stringstream compressed_encoded;
std::stringstream decompressed;
compressed_encoded << compressedstr;
/** first decode then decompress **/
std::string compressed = base64_decode(compressed_encoded.str());
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::zlib_decompressor());
in.push(compressed);
uncompressedstr=decompressed.str();
}
and I got a bunch of errors , I'm using VS 2013 on a Windows 7 machine(I was trying compatible of Win 7 even WinXP)
any idea how to resolve this problem ? thank you so much
the error output is:
1>------ Rebuild All started: Project: myproject, Configuration: Debug Win32 ------
1> stdafx.cpp
1> myproject.cpp
1>d:\cpptestnew\myproject\myproject.cpp(548): warning C4018: '<' : signed/unsigned mismatch
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2039: 'category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::iostreams::detail::member_category<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>' being compiled
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(274) : see reference to class template instantiation 'boost::mpl::eval_if<boost::mpl::and_<boost::iostreams::is_std_io<std::string>,boost::mpl::not_<boost::iostreams::detail::is_boost<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>,boost::mpl::true_,boost::mpl::true_,boost::mpl::true_>,boost::iostreams::select<boost::iostreams::is_filebuf<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::filebuf_tag,boost::iostreams::is_ifstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ifstream_tag,boost::iostreams::is_ofstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ofstream_tag,boost::iostreams::is_fstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::fstream_tag,boost::iostreams::is_stringbuf<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::stringbuf_tag,boost::iostreams::is_istringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::istringstream_tag,boost::iostreams::is_ostringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ostringstream_tag,boost::iostreams::is_stringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::stringstream_tag,boost::iostreams::is_streambuf<T>,boost::iostreams::generic_streambuf_tag,boost::iostreams::is_iostream<T>,boost::iostreams::generic_iostream_tag,boost::iostreams::is_istream<T>,boost::iostreams::generic_istream_tag,boost::iostreams::is_ostream<T>,boost::iostreams::generic_ostream_tag>,boost::iostreams::detail::member_category<T>>' being compiled
1> with
1> [
1> T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(236) : see reference to class template instantiation 'boost::iostreams::category_of<T>' being compiled
1> with
1> [
1> T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(216) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(216) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(499) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push<T>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(499) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push<T>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(488) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(488) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\cpptestnew\myproject\myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\cpptestnew\myproject\myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2146: syntax error : missing ';' before identifier 'type'
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2208: 'boost::type' : no members defined using this type
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): fatal error C1903: unable to recover from previous error(s); stopping compilation
1> base64.cpp
1> Generating Code...
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
You need to examine the error output in detail to determine what the problem is.
If we start from the end of the first error message:
myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
This tells you where in your code the error originates from. push only accepts a boost::iostreams device or a std::iostream. You are passing a std::string. If we now look at the start of the error message it starts to make more sense (if you know a little about how boost::iostreams works):
'category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
push is trying to work out what to do with your passed argument, it isn't a std::iostream so it assumes it is a boost::iostreams device, all devices export a category member which defines what the devices can be used for. std::string doesn't export such a member so causes an error.
Assuming base64_decode returns a std::string then you can change compressed to a stream and therefore a valid parameter for push by doing:
std::stringstream compressed{base64_decode(compressed_encoded.str())};

`boost` `Signal2` library conflicts with Microsoft memory leak detection?

I have portable Linux/Windows application. I use boost Signal2 library to implement events system.
Microsoft has built-in memory leak detection feature in Visual C++. You have to include some code at the very beginning of any source file to replace normal malloc and new with theirs debug versions, and these debug memory management functions generate memory leak report when application exits. The code follows:
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif
When I include this code, the program stops to compile. Error messages are not understandable and don't even point to source file where the error occurred (they point to boost headers, but not to my program headers or code files). Error report follows:
D:\src\open-source\boost\boost/variant/detail/initializer.hpp(122): error C2061: syntax error : identifier 'dest'
1> D:\src\open-source\boost\boost/variant/detail/initializer.hpp(116) : while compiling class template member function 'int boost::detail::variant::make_initializer_node::apply<T1,T2>::initializer_node::initialize(void *,boost::shared_ptr<void> &&)'
1> with
1> [
1> T1=boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>
1> , T2=boost::mpl::l_iter<boost::mpl::list2<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr>>
1> ]
1> D:\src\open-source\boost\boost/variant/variant.hpp(1559) : see reference to function template instantiation 'int boost::detail::variant::make_initializer_node::apply<T1,T2>::initializer_node::initialize(void *,boost::shared_ptr<void> &&)' being compiled
1> with
1> [
1> T1=boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>
1> , T2=boost::mpl::l_iter<boost::mpl::list2<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr>>
1> ]
1> D:\src\open-source\boost\boost/variant/detail/initializer.hpp(76) : see reference to class template instantiation 'boost::detail::variant::make_initializer_node::apply<T1,T2>::initializer_node' being compiled
1> with
1> [
1> T1=boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>
1> , T2=boost::mpl::l_iter<boost::mpl::list2<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr>>
1> ]
1> D:\src\open-source\boost\boost/variant/variant.hpp(1339) : see reference to class template instantiation 'boost::detail::variant::make_initializer_node::apply<T1,T2>::initializer_node' being compiled
1> with
1> [
1> T1=boost::mpl::pair<boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::l_iter<boost::mpl::list2<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr>>>::initializer_node,boost::mpl::int_<1>>
1> , T2=boost::mpl::l_iter<boost::mpl::list1<boost::signals2::detail::foreign_void_shared_ptr>>
1> ]
1> D:\src\open-source\boost\boost/variant/variant.hpp(1555) : see reference to class template instantiation 'boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::initializer' being compiled
1> D:\src\open-source\boost\boost/variant/variant.hpp(1732) : see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::convert_construct<boost::shared_ptr<void>>(T &&,int,boost::mpl::false_)' being compiled
1> with
1> [
1> T=boost::shared_ptr<void>
1> ]
1> D:\src\open-source\boost\boost/variant/variant.hpp(1732) : see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::convert_construct<boost::shared_ptr<void>>(T &&,int,boost::mpl::false_)' being compiled
1> with
1> [
1> T=boost::shared_ptr<void>
1> ]
1> D:\src\open-source\boost\boost/signals2/slot_base.hpp(49) : see reference to function template instantiation 'boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::variant<boost::shared_ptr<void>>(T &&,void *,void *)' being compiled
1> with
1> [
1> T=boost::shared_ptr<void>
1> ]
1> D:\src\open-source\boost\boost/signals2/slot_base.hpp(49) : see reference to function template instantiation 'boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::variant<boost::shared_ptr<void>>(T &&,void *,void *)' being compiled
1> with
1> [
1> T=boost::shared_ptr<void>
1> ]
Is there any workaround to use boost and still use memory leak detection on Windows?

How can I get rid of gtest compiler warning C4800 ('int' : forcing value to bool 'true' or 'false'")

I've inherited some unit test code (VS2008 c++ for a WinCE-based smart device) that uses gtest. When I compile the unit tests I get all kinds of C4800 warnings about forcing ints into bools. What's weird is that the only gtest calls in the module generating the warnings are to EXPECT_STREQ.
Is this a (minor) bug in gtest, it's doing EXPECT_STREQ in a way that confuses VS2008/WinCE?
We are using gtest version 1.6, does anyone know if version 1.7 works for WinCE?
==============
1>C:\googletest\include\gtest/internal/gtest-port.h(1031) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1> C:\googletest\include\gtest/internal/gtest-param-util.h(321) : see reference to function template instantiation 'Derived *testing::internal::CheckedDowncastToActualType<const testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator,const testing::internal::ParamIteratorInterface<T>>(Base *)' being compiled
1> with
1> [
1> Derived=const testing::internal::ValuesInIteratorRangeGenerator<ParamType>::Iterator,
1> T=ParamType,
1> Base=const testing::internal::ParamIteratorInterface<bool>
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(314) : while compiling class template member function 'bool testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator::Equals(const testing::internal::ParamIteratorInterface<T> &) const'
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(276) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator' being compiled
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(275) : while compiling class template member function 'testing::internal::ParamIteratorInterface<T> *testing::internal::ValuesInIteratorRangeGenerator<T>::Begin(void) const'
1> with
1> [
1> T=bool
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(314) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>' being compiled
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(319) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<const T*>(ForwardIterator,ForwardIterator)' being compiled
1> with
1> [
1> T=bool,
1> ForwardIterator=const bool *
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util-generated.h(99) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<T,2>(const T (&)[2])' being compiled
1> with
1> [
1> T=bool
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(1221) : see reference to function template instantiation 'testing::internal::ValueArray2<T1,T2>::operator testing::internal::ParamGenerator<T>(void) const<bool>' being compiled
1> with
1> [
1> T1=bool,
1> T2=bool,
1> T=bool
1> ]
Warning C4800 is given when an int is put into a variable of type bool. The documentation for warning C4800 states that it is a performance warning so you probably don't have to worry about it.
If you want hide the warning you can use MSVC's #pragma warning(disable:4800) to disable the warning.
So it would look like this
#pragma warning(disable:4800) //Disable the warning
... // Code that gives warning here
#pragma warning(default:4800) //Stop suppressing the warning
You can see the documentation for #pragma warning here.

std thread sleep_for doesnt work with some chrono::duration

I am using VS2012 and I have problem with following example:
#include <chrono>
#include <thread>
int main()
{
// doesn't compile and I don't understand why:
std::this_thread::sleep_for(std::chrono::duration<double>(0.1));
// I can use this but still I would like to know the reason:
std::this_thread::sleep_for(std::chrono::duration<long long, std::milli>(100));
return 0;
}
Both duration should be valid. And it is possible to use them in different context.
Compile error:
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(749): error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const std::chrono::duration<_Rep>' (or there is no acceptable conversion)
1> with
1> [
1> _Rep=double
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(166): could be 'std::chrono::duration<_Rep,_Period> &std::chrono::duration<_Rep,_Period>::operator +=(const std::chrono::duration<_Rep,_Period> &)'
1> with
1> [
1> _Rep=__int64,
1> _Period=std::nano
1> ]
1> while trying to match the argument list '(std::chrono::nanoseconds, const std::chrono::duration<_Rep>)'
1> with
1> [
1> _Rep=double
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\thread(164) : see reference to function template instantiation 'xtime std::_To_xtime<double,std::ratio<_Nx>>(const std::chrono::duration<_Rep> &)' being compiled
1> with
1> [
1> _Nx=0x01,
1> _Rep=double
1> ]
1> i:\prog\.c++\test2\test2\source.cpp(13) : see reference to function template instantiation 'void std::this_thread::sleep_for<double,std::ratio<_Nx>>(const std::chrono::duration<_Rep> &)' being compiled
1> with
1> [
1> _Nx=0x01,
1> _Rep=double
1> ]
1>
1>Build FAILED.
Any help appreciated.
It is VS2012 compiler issue. Not 100% sure if it is this one (thx Praetorian). But it is possible to compile without problem with gcc 4.9.2. I should've think about trying it before I ask.

Failure when casting NULL/nullptr to std::function<>&

This code fails to build in VC2013: (EDIT: I'm not asking why it fails to build)
#include <functional>
struct MyStruct
{
std::function<void()> m_Func;
MyStruct( const std::function<void()>& func) : m_Func(func) {}
};
int main()
{
MyStruct rc( NULL );
return 0;
}
With error:
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(283): error C2064: term does not evaluate to a function taking 0 arguments
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<int,false>::_ApplyX<_Rx,>(void)' being compiled
1> with
1> [
1> _Ret=void
1> , _Rx=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<int,false>::_ApplyX<_Rx,>(void)' being compiled
1> with
1> [
1> _Ret=void
1> , _Rx=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(226) : while compiling class template member function 'void std::_Func_impl<_MyWrapper,_Alloc,_Ret,>::_Do_call(void)'
1> with
1> [
1> _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Ret=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(495) : see reference to class template instantiation 'std::_Func_impl<_MyWrapper,_Alloc,_Ret,>' being compiled
1> with
1> [
1> _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Ret=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset_alloc<_Ty,std::allocator<std::_Func_class<_Ret,>>>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset_alloc<_Ty,std::allocator<std::_Func_class<_Ret,>>>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset<_Ty>(_Fty &&)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset<_Ty>(_Fty &&)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> ]
1> f:\work\teststdfunction\teststdfunction.cpp(16) : see reference to function template instantiation 'std::function<void (void)>::function<int>(_Fx &&)' being compiled
1> with
1> [
1> _Fx=int
1> ]
1> f:\work\teststdfunction\teststdfunction.cpp(16) : see reference to function template instantiation 'std::function<void (void)>::function<int>(_Fx &&)' being compiled
1> with
1> [
1> _Fx=int
1> ]
(Note the '_Fx=int' at the last two reported errors).
I can live with that, as changing MyStruct rc(NULL) to MyStruct rc(nullptr) solves the error. Two things however remain a mystery:
1) Removing the const qualifier from MyStruct ctor (MyStruct( std::function<void()>& func) gives a very, very different error:
1>f:\work\main\dev\common\teststdfunction\teststdfunction\teststdfunction.cpp(16):
error C2664: 'MyStruct::MyStruct(const MyStruct &)' : cannot convert
argument 1 from 'int' to 'std::function &'
Which makes more sense than the original error, and now fixing NULL to nullptr doesn't solve it. Why does int (or nullptr) refuse to cast to std::function<>& but agree to cast to a const std::function<>& ?
2) The original code compiles and works as expected in VS2010. Is it an obscure VS2010 library bug?
EDIT:
As far as the const/non const question goes, I now think the casting involved and potential type mismatch are probably a red herring. The argument passed - either NULL or nullptr - is a literal and thus a const. It just cannot bind to a non const reference. For example:
const int& a = 8; // Ok
int& b = 9; // error C2440: 'initializing' : cannot convert from 'int' to 'int &'
Does that sound right? Am I still missing something?
The special here has to do with constructor template constraints and other implicit conversions.
The reason why nullptr works is because std::function has a particular constructor taking it. This constructor will always be the best match for that argument because function templates are ranked as lower preference, all else being equal.
Normally, 0 will implicitly convert to nullptr and that's fine. The problem is that it can also be passed to the unconstrained function template constructor which constructs from function objects. This does not require an implicit conversion, so all is not equal, so this constructor is preferred- which results in the error that you see that int is not a valid function object.
libstdc++ and libc++ don't not exhibit this behaviour because they have implemented the C++14 fix for this problem, which constrains the constructor. C++11 did not so this behaviour is quite conforming for a C++11 implementation.
This kind of issue is why NULL is a terrible thing that you shouldn't use. In fact, the VS2010 team had to rush nullptr out the door as an additional feature in the last minute because NULL interacts so badly with every other feature in C++, ever, and especially with C++11.
For const vs non-const references, other answers have explained that issue adequately.
There are other WTFs you can find when using std::function without the constrained constructor fix shipped in C++14- this isn't the only one. The long and short is that it's a defect in the C++11 Standard, and not in VS. VS2010 compiling it is probably a compiler overload resolution bug.
Casting a T to a U& never works, and that's intentionally. You can cast to a U const&. The reason is that changes to the temporary U object wouldn't propagate back to the T value.
VS2010 is slightly buggy in this respect, and did allow the cast (but with the proper settings, will warn about it)