Opened 12 years ago
Closed 5 years ago
#4658 closed Bugs (wontfix)
(boost::format("%u") % (unsigned char)2).str(); error result
Reported by: | anonymous | Owned by: | James E. King, III |
---|---|---|---|
Milestone: | Component: | format | |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
(boost::format("%u") % (unsigned char)2).str(); (boost::format("%d") % (char)2).str(); error result
Change History (3)
comment:1 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 5 years ago
#9360 also details the following, which I verified:
// https://svn.boost.org/trac10/ticket/9360 unsigned char c = 0x55; s = (boost::format("0x%02X") % c).str(); BOOST_CHECK_EQUAL(std::string("0x55"), s); Running 1 test case... format_test3.cpp(134): error: in "test_main_caller(_argc,_argv_)": check std::string("0x55") == s has failed [0x55 != 0x0U]
If you change the type of c to an unsigned short, or unsigned int, then the check passes, so it is specific to char handling, just as the original report here.
comment:3 by , 5 years ago
Milestone: | Boost 1.44.0 |
---|---|
Resolution: | → wontfix |
Status: | assigned → closed |
Resolving this as wontfix because it is working as designed. The argument type modifiers are ignored completely by Boost.Format for type safety reasons as defined in the documentation for the library.
A workaround is to cast the value to an integer before adding it with operator %.
I'm thinking about changing this behavior in future releases, and allowing full ISO C99 compatibility, possibly by simply leveraging snprintf when a C style format specification with a conversion specifier is used. Anything that happens in this area would be fully backwards compatible through preprocessor macros. We'll see.
Is this a fair test to represent the report? There wasn't much to go on: