Ticket #6635 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

Boost.Locale UTF encode function passes wrong type to output iterator

Reported by: jason.erb@… Owned by: artyom
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.


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

Change History

Changed 5 years ago by jason.erb@…

Patch for #6635

comment:1 Changed 5 years ago by artyom

  • Status changed from new to assigned
  • Severity changed from Problem to Cosmetic
  • Milestone changed from To Be Determined to Boost 1.50.0

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

Fixed in changeset #78304 in trunk

comment:4 Changed 5 years ago by artyom

  • Status changed from assigned to closed
  • Resolution set to fixed

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

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

Note: See TracTickets for help on using tickets.