Opened 6 years ago

Closed 5 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:


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@… 6 years ago.
Patch for #6635

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by jason.erb@…

Attachment: 6635.patch added

Patch for #6635

comment:1 Changed 6 years ago by Artyom Beilis

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 Changed 6 years ago by Jason Erb <jason.erb@…>

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 Changed 5 years ago by Artyom Beilis

Fixed in changeset #78304 in trunk

comment:4 Changed 5 years ago by Artyom Beilis

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Artyom Beilis.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.