467. char_traits::lt(), compare(), and memcmp()

Section: [char.traits.specializations.char] Status: CD1 Submitter: Martin Sebor Opened: 2004-06-28 Last modified: 2016-01-28 10:19:27 UTC

Priority: Not Prioritized

View all issues with CD1 status.


Table 37 describes the requirements on Traits::compare() in terms of those on Traits::lt()., p6 requires char_traits<char>::lt() to yield the same result as operator<(char, char).

Most, if not all, implementations of char_traits<char>::compare() call memcmp() for efficiency. However, the C standard requires both memcmp() and strcmp() to interpret characters under comparison as unsigned, regardless of the signedness of char. As a result, all these char_traits implementations fail to meet the requirement imposed by Table 37 on compare() when char is signed.

Read email thread starting with c++std-lib-13499 for more.

Proposed resolution:

Change, p6 from

The two-argument members assign, eq, and lt are defined identically to the built-in operators =, ==, and < respectively.


The two-argument member assign is defined identically to the built-in operator =. The two argument members eq and lt are defined identically to the built-in operators == and < for type unsigned char.

[Redmond: The LWG agreed with this general direction, but we also need to change eq to be consistent with this change. Post-Redmond: Martin provided wording.]