Opened 11 years ago
Closed 10 years ago
#6635 closed Bugs (fixed)
Boost.Locale UTF encode function passes wrong type to output iterator
| Reported by: | Owned by: | Artyom Beilis | |
|---|---|---|---|
| Milestone: | Boost 1.50.0 | Component: | locale |
| Version: | Boost 1.49.0 | Severity: | Cosmetic |
| Keywords: | Boost.Locale encode UTF | Cc: |
Description
When passing a char output iterator (such as std::back_insert_iterator<std::string>) to boost::locale::utf::utf_traits<char>::encode, the compiler (Apple LLVM compiler 3.1 in Xcode 4.3 with extra warnings enabled) emits a warning about assigning unsigned int to char. The code incorrectly attempts to write the code unit to the output as a code_point instead of a CharType.
The attached patch performs a safe static cast of each code unit to CharType as it is written to the output iterator.
Attachments (1)
Change History (5)
by , 11 years ago
| Attachment: | 6635.patch added |
|---|
comment:1 by , 11 years ago
| Milestone: | To Be Determined → Boost 1.50.0 |
|---|---|
| Severity: | Problem → Cosmetic |
| Status: | new → assigned |
AFAIK there should be no warning for conversion between integral and character type. It is done all over the code in all places.
Casting to char_type would eliminate the warning but I'm not sure it is the correct approach.
I'll think about it.
comment:2 by , 11 years ago
Thanks for looking into this. Here is the specific message:
error: implicit conversion loses integer precision: 'code_point' (aka 'unsigned int') to 'const char' [-Werror,-Wconversion]
I have used various boost libraries for a long time with these warnings enabled and this is the first library in which I have hit this problem. In my view, the cast is entirely appropriate in this case: the user has specified CharType as the code unit type, so the code units sent to the output iterator should be of this type.
comment:4 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |

Patch for #6635