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?
Related
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())};
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
The following piece of code throwing warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning). Moving #define true and false after string and map header inclusions not throwing this warning. This is a sample code and in the actual code #define true and false are defined in one of our product library header files. So I want to understand why this warning is thrown by visual studio and why it is going away when #define moved after string and map header inclusions.
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#include <string>
#include <map>
int main()
{
std::map<std::string, std::string> pair;
pair.insert(std::make_pair("Key1", "Value1"));
return 0;
}
Full details of warning:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\utility(144): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree(1801) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool>::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,int,void>(_Other1 &&,_Other2 &&)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,std::string>>>>
1> , _Other2=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree(1801) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool>::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,int,void>(_Other1 &&,_Other2 &&)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,std::string>>>>
1> , _Other2=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree(1160) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::_Insert_nohint<std::pair<const _Kty,_Ty>&,std::_Tree_node<std::pair<const _Kty,_Ty>,void *>*>(bool,_Valty,_Nodety)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Pr=std::less<std::string>
1> , _Alloc=std::allocator<std::pair<const std::string,std::string>>
1> , _Valty=std::pair<const std::string,std::string> &
1> , _Nodety=std::_Tree_node<std::pair<const std::string,std::string>,void *> *
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xtree(1160) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::_Insert_nohint<std::pair<const _Kty,_Ty>&,std::_Tree_node<std::pair<const _Kty,_Ty>,void *>*>(bool,_Valty,_Nodety)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Pr=std::less<std::string>
1> , _Alloc=std::allocator<std::pair<const std::string,std::string>>
1> , _Valty=std::pair<const std::string,std::string> &
1> , _Nodety=std::_Tree_node<std::pair<const std::string,std::string>,void *> *
1> ]
1> Source.cpp(41) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::insert<std::pair<const char *,const char *>>(_Valty &&)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Pr=std::less<std::string>
1> , _Alloc=std::allocator<std::pair<const std::string,std::string>>
1> , _Valty=std::pair<const char *,const char *>
1> ]
1> Source.cpp(41) : see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const _Kty,_Ty>>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::insert<std::pair<const char *,const char *>>(_Valty &&)' being compiled
1> with
1> [
1> _Kty=std::string
1> , _Ty=std::string
1> , _Pr=std::less<std::string>
1> , _Alloc=std::allocator<std::pair<const std::string,std::string>>
1> , _Valty=std::pair<const char *,const char *>
1> ]
I'm not condoning your macros, but the answer to your question is that your check isn't nearly complete. In C++, true and false are keywords, not macros like in C's stdbool.h header. So checking if they aren't defined is always going to be true. If you want to C++-proof those macros, the condition should be something like this:
#if !defined(__cplusplus) && !defined(true)
#define true 1
#endif
__cplusplus is a standard macro that is defined by the implementation when a TU is compiled as C++. The added check will prevent messing up with those keywords, and breaking any standard library headers that use them.
You say
the #defines are declared in one of our product header files(not written by me)
Then, you should tell the guy who wrote this code to modify it. It's probably pure C code (where true/false are not defined) and he decided to declare them, why not, but then, I thing the good strategy would be for him not to use the standard names true/false that end up confliciting with standard ones in your case. He should use MyTrue/MyFalse (or whetever name that would make sense in the context).
So just (or ask him to) go in the code where true/false was defined, replace all occurence of "true" by "MyTrue", all "false" by "MyFalse", the code behaviour should not be impacted. The conflict will go away as well as the warning!
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.
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.