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: jason.erb@… 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)

6635.patch (2.6 KB ) - added by jason.erb@… 11 years ago.
Patch for #6635

Download all attachments as: .zip

Change History (5)

by jason.erb@…, 11 years ago

Attachment: 6635.patch added

Patch for #6635

comment:1 by Artyom Beilis, 11 years ago

Milestone: To Be DeterminedBoost 1.50.0
Severity: ProblemCosmetic
Status: newassigned

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 Jason Erb <jason.erb@…>, 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:3 by Artyom Beilis, 10 years ago

Fixed in changeset #78304 in trunk

comment:4 by Artyom Beilis, 10 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.