Opened 11 years ago
Last modified 5 years ago
#5598 new Bugs
boost/property_tree/detail/json_parser_write.hpp:35: warning: comparison is always true due to limited range of data type
Reported by: | Owned by: | Sebastian Redl | |
---|---|---|---|
Milestone: | To Be Determined | Component: | property_tree |
Version: | Boost 1.46.1 | Severity: | Problem |
Keywords: | Cc: | mika.fischer@…, mateusz@… |
Description
Here is the relevant output:
cc1plus: warnings being treated as errors gcc41_64/include/boost/property_tree/detail/json_parser_write.hpp: In function 'std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT> > boost::property_tree::json_parser::create_escapes(const std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT> >&) [with Ch = char]': gcc41_64/include/boost/property_tree/detail/json_parser_write.hpp:78: instantiated from 'void boost::property_tree::json_parser::write_json_helper(std::basic_ostream<typename Ptree::key_type::value_type, std::char_traits<typename Ptree::key_type::value_type> >&, const Ptree&, int, bool) [with Ptree = boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]' gcc41_64/include/boost/property_tree/detail/json_parser_write.hpp:162: instantiated from 'void boost::property_tree::json_parser::write_json_internal(std::basic_ostream<typename Ptree::key_type::value_type, std::char_traits<typename Ptree::key_type::value_type> >&, const Ptree&, const std::string&, bool) [with Ptree = boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]' gcc41_64/include/boost/property_tree/json_parser.hpp:98: instantiated from 'void boost::property_tree::json_parser::write_json(std::basic_ostream<typename Ptree::key_type::value_type, std::char_traits<typename Ptree::key_type::value_type> >&, const Ptree&, bool) [with Ptree = boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]' json.cc:36: instantiated from here gcc41_64/include/boost/property_tree/detail/json_parser_write.hpp:35: warning: comparison is always true due to limited range of data type make: *** [json.o] Error 1
In the big if() statement, *b (of type Ch, which is char) is being compared with 0xFF.
Attachments (3)
Change History (14)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Sorry, I was stating that in my case, Ch was char. Yes, it could be wchar_t as well. However, in the case of Ch being char, the warning is correct.
comment:3 by , 11 years ago
Please create a comparison function for wide characters and specialize for Ch=char or unsigned char to not perform the comparison *b <= 0xff.
Thanks.
by , 10 years ago
Attachment: | json_parser_write.hpp.diff added |
---|
Silence the warning from GCC about a comparison that is always true due to to the limits of the type by creating specializations of the check for char and unsigned char.
comment:4 by , 10 years ago
Cc: | added |
---|
follow-up: 8 comment:5 by , 9 years ago
@Shane
I attached an updated version of the patch to this tracker.
However, the patch fails on my project because I had a double include of <boost/property_tree/json_parser.hpp>
in two different compilation units. This caused my program build to fail due to a multiple definition for the check_is_ascii
method. I created a simple test case that can be used to reproduce/debug the problem, I can send it to you if you want to.
If I have a time, I will check how this could be solved. For now, I just ensured that the json_parser.hpp
file is included only once in my codebase.
Expect for this, your patch seems to work like a charm. Will report back if I find any problem with it.
Regards, Matt
follow-up: 7 comment:6 by , 9 years ago
Cc: | added |
---|
comment:7 by , 9 years ago
Replying to mloskot: I think, for explicitly instantiated template functions keyword 'inline' would fix the problem
comment:8 by , 9 years ago
Replying to Matthieu Vachon <matthieu.o.vachon@…>: Any chance you've tried out adding 'inline' as suggested in 7?
Also, will this change make it into 1.55.0?
comment:10 by , 7 years ago
As of Boost 1.61.0 Beta 1 RC2, the file has changed from boost/property_tree/detail/json_parser_write.hpp to boost/property_tree/json_parser/detail/write.hpp
comment:11 by , 5 years ago
In 1.64.0, the issue happens again, the fix in json_parser_write.hpp.2.diff is lost.
Ch might be wchar_t.
The warning can be suppressed by casting to some large integer type first, but I feel that the warning here is overeager and a bug.