Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix C4267 and C4244 warnings in Visual Studio 2017 compile #29040

Merged
merged 2 commits into from
Mar 27, 2019

Conversation

KarateSnoopy
Copy link
Contributor

Summary

SUMMARY: Build "Fix C4267 and C4244 warnings in Visual Studio 2017 compile"

Purpose of change

When compiling with VS2017 15.9.10, these warnings appear:

Warning	C4267	'argument': conversion from 'size_t' to 'int', possible loss of data	Cataclysm-vcpkg	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0	881	
Warning	C4244	'initializing': conversion from '_Ty' to '_Ty2', possible loss of data	Cataclysm-vcpkg	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\utility	173	
Warning	C4244	'initializing': conversion from '_Ty' to '_Ty2', possible loss of data	Cataclysm-vcpkg	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\utility	173	
Warning	C4267	'initializing': conversion from 'size_t' to '_Objty', possible loss of data	Cataclysm-vcpkg	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0	881	
Warning	C4267	'argument': conversion from 'size_t' to 'int', possible loss of data	Cataclysm-vcpkg	c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0	881	

Describe the solution

Fixed various size_t casting bugs.

Also vitamins.get_float() returns a double so

    std::map<vitamin_id, float> vit 

needed to be

    std::map<vitamin_id, double> vit

and related places needed to change to double.

Additional context

Full warning log without this fix below in case anyone wants detail.

1>mutation_data.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\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=double
1>        ]
1>        and
1>        [
1>            _Ty2=float
1>        ]

1>mutation_type.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<string_id<vitamin>,double,0>(_Other1 &&,_Other2 &&) noexcept' being compiled
1>        with
1>        [
1>            _Kty=vitamin_id,
1>            _Ty=float,
1>            _Other1=vitamin_id,
1>            _Other2=double
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<string_id<vitamin>,double,0>(_Other1 &&,_Other2 &&) noexcept' being compiled
1>        with
1>        [
1>            _Kty=vitamin_id,
1>            _Ty=float,
1>            _Other1=vitamin_id,
1>            _Other2=double
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(984): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,string_id<vitamin>,double>(_Alloc &,_Objty *const ,string_id<vitamin> &&,double &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<std::_Tree_node<std::pair<const vitamin_id,float>,std::_Default_allocator_traits<std::allocator<std::pair<const vitamin_id,float>>>::void_pointer>>,
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Objty=std::pair<const vitamin_id,float>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(983): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,string_id<vitamin>,double>(_Alloc &,_Objty *const ,string_id<vitamin> &&,double &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<std::_Tree_node<std::pair<const vitamin_id,float>,std::_Default_allocator_traits<std::allocator<std::pair<const vitamin_id,float>>>::void_pointer>>,
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Objty=std::pair<const vitamin_id,float>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(1155): note: see reference to function template instantiation 'std::_Tree_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer> *std::_Tree_comp_alloc<_Traits>::_Buynode<string_id<vitamin>,double>(string_id<vitamin> &&,double &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Traits=std::_Tmap_traits<vitamin_id,float,std::less<vitamin_id>,std::allocator<std::pair<const vitamin_id,float>>,false>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(1155): note: see reference to function template instantiation 'std::_Tree_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer> *std::_Tree_comp_alloc<_Traits>::_Buynode<string_id<vitamin>,double>(string_id<vitamin> &&,double &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Traits=std::_Tmap_traits<vitamin_id,float,std::less<vitamin_id>,std::allocator<std::pair<const vitamin_id,float>>,false>
1>        ]
1>f:\git\cataclysm-dda\src\mutation_data.cpp(310): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,float,_Pr,_Alloc,false>>::emplace<vitamin_id,double>(vitamin_id &&,double &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Kty=vitamin_id,
1>            _Pr=std::less<vitamin_id>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>
1>        ]
1>f:\git\cataclysm-dda\src\mutation_data.cpp(310): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,float,_Pr,_Alloc,false>>::emplace<vitamin_id,double>(vitamin_id &&,double &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Kty=vitamin_id,
1>            _Pr=std::less<vitamin_id>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>
1>        ]
1>f:\git\cataclysm-dda\src\units.h(278): note: see reference to class template instantiation 'units::quantity<int,units::volume_in_milliliter_tag>' being compiled


1>lightmap.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): warning C4267: 'initializing': conversion from 'size_t' to '_Objty', possible loss of data
1>        with
1>        [
1>            _Objty=int
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(902): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,unsigned __int64>(_Alloc &,_Objty *const ,unsigned __int64 &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Ty=int,
1>            _Objty=int
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(902): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,unsigned __int64>(_Alloc &,_Objty *const ,unsigned __int64 &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Ty=int,
1>            _Objty=int
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(919): note: see reference to function template instantiation 'void std::vector<int,std::allocator<_Ty>>::_Emplace_back_with_unused_capacity<unsigned __int64>(unsigned __int64 &&)' being compiled
1>        with
1>        [
1>            _Ty=int
1>        ]


1>item_factory.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(902): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,size_t&,bool,int,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(_Alloc &,_Objty *const ,size_t &,bool &&,int &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<uilist_entry>,
1>            _Ty=uilist_entry,
1>            _Objty=uilist_entry
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(902): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,size_t&,bool,int,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(_Alloc &,_Objty *const ,size_t &,bool &&,int &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<uilist_entry>,
1>            _Ty=uilist_entry,
1>            _Objty=uilist_entry
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\vector(919): note: see reference to function template instantiation 'void std::vector<uilist_entry,std::allocator<_Ty>>::_Emplace_back_with_unused_capacity<size_t&,bool,int,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(size_t &,bool &&,int &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1>        with
1>        [
1>            _Ty=uilist_entry
1>        ]
1>f:\git\cataclysm-dda\src\item_factory.cpp(2651): note: see reference to function template instantiation 'void std::vector<uilist_entry,std::allocator<_Ty>>::emplace_back<size_t&,bool,int,std::basic_string<char,std::char_traits<char>,std::allocator<char>>&>(size_t &,bool &&,int &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' being compiled
1>        with
1>        [
1>            _Ty=uilist_entry
1>        ]



1>consumption.cpp
1>c:\program files (x86)\microsoft visual studio\2017\community\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=float
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<_Ty1&,int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=vitamin_id,
1>            _Ty=float,
1>            _Ty1=vitamin_id,
1>            _Other1=const vitamin_id &,
1>            _Other2=int
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xmemory0(881): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<_Ty1&,int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=vitamin_id,
1>            _Ty=float,
1>            _Ty1=vitamin_id,
1>            _Other1=const vitamin_id &,
1>            _Other2=int
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(984): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,_Ty1&,int>(_Alloc &,_Objty *const ,_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<std::_Tree_node<std::pair<const vitamin_id,float>,std::_Default_allocator_traits<std::allocator<std::pair<const vitamin_id,float>>>::void_pointer>>,
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Ty1=vitamin_id,
1>            _Objty=std::pair<const vitamin_id,float>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(983): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<_Ty,_Ty1&,int>(_Alloc &,_Objty *const ,_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Alloc=std::allocator<std::_Tree_node<std::pair<const vitamin_id,float>,std::_Default_allocator_traits<std::allocator<std::pair<const vitamin_id,float>>>::void_pointer>>,
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Ty1=vitamin_id,
1>            _Objty=std::pair<const vitamin_id,float>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(1155): note: see reference to function template instantiation 'std::_Tree_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer> *std::_Tree_comp_alloc<_Traits>::_Buynode<_Ty1&,int>(_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Traits=std::_Tmap_traits<vitamin_id,float,std::less<vitamin_id>,std::allocator<std::pair<const vitamin_id,float>>,false>,
1>            _Ty1=vitamin_id
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(1155): note: see reference to function template instantiation 'std::_Tree_node<_Ty,std::_Default_allocator_traits<_Alloc>::void_pointer> *std::_Tree_comp_alloc<_Traits>::_Buynode<_Ty1&,int>(_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Traits=std::_Tmap_traits<vitamin_id,float,std::less<vitamin_id>,std::allocator<std::pair<const vitamin_id,float>>,false>,
1>            _Ty1=vitamin_id
1>        ]
1>f:\git\cataclysm-dda\src\consumption.cpp(281): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,float,_Pr,_Alloc,false>>::emplace<_Ty1&,int>(_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Kty=vitamin_id,
1>            _Pr=std::less<vitamin_id>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Ty1=vitamin_id
1>        ]
1>f:\git\cataclysm-dda\src\consumption.cpp(281): note: see reference to function template instantiation 'std::pair<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>,bool> std::_Tree<std::_Tmap_traits<_Kty,float,_Pr,_Alloc,false>>::emplace<_Ty1&,int>(_Ty1 &,int &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const vitamin_id,float>,
1>            _Kty=vitamin_id,
1>            _Pr=std::less<vitamin_id>,
1>            _Alloc=std::allocator<std::pair<const vitamin_id,float>>,
1>            _Ty1=vitamin_id
1>        ]

@KarateSnoopy
Copy link
Contributor Author

Looks like the gorgon-ghprb failed with

22:35:26 astyle regressions found.
22:35:26 Formatted src/trait_group.cpp Formatted src/item_factory.cpp Formatted src/lightmap.cpp
22:35:26 Makefile:993: recipe for target 'astyle-check' failed
22:35:26 make: *** [astyle-check] Error 1
22:35:26 Build step 'Conditional step (single)' marked build as failure

Can anyone explain what that means and how to fix?

@ZhilkinSerg
Copy link
Contributor

We use a set of agreed rules in Artistic Style for code formatting. See instruction how to do it in VS in #24006

@KarateSnoopy
Copy link
Contributor Author

Thanks, I'll get it fixed up

@ZhilkinSerg ZhilkinSerg added Code: Build Issues regarding different builds and build environments OS: Windows Issues related to Windows operating system [C++] Changes (can be) made in C++. Previously named `Code` labels Mar 27, 2019
@KarateSnoopy
Copy link
Contributor Author

KarateSnoopy commented Mar 27, 2019

Now it looks like gorgon-ghprb failed with

23:40:44 Pruning obsolete local branches
23:40:44 Fetching upstream changes from https://github.com/CleverRaven/Cataclysm-DDA.git
23:40:44  > /usr/bin/git fetch --tags --progress https://github.com/CleverRaven/Cataclysm-DDA.git +refs/heads/master:refs/remotes/origin/master +refs/pull/2*:refs/remotes/origin/pr/2* --prune --depth=1
23:50:44 ERROR: Timeout after 10 minutes
23:50:44 ERROR: Error fetching remote repo 'origin'
23:50:44 hudson.plugins.git.GitException: Failed to fetch from https://github.com/CleverRaven/Cataclysm-DDA.git
23:50:44 	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:888)

Is there some fix for this or just kick it off again somehow?

@ZhilkinSerg ZhilkinSerg self-assigned this Mar 27, 2019
@ZhilkinSerg ZhilkinSerg merged commit 021895a into CleverRaven:master Mar 27, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Mar 27, 2019
@KarateSnoopy KarateSnoopy deleted the fix-vs-warnings branch March 27, 2019 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Build Issues regarding different builds and build environments OS: Windows Issues related to Windows operating system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants