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

Section: 24.2.3.1 [char.traits.specializations.char] Status: CD1 Submitter: Martin Sebor Opened: 2004-06-28 Last modified: 2016-02-10

Priority: Not Prioritized

View all issues with CD1 status.

Discussion:

Table 37 describes the requirements on Traits::compare() in terms of those on Traits::lt(). 21.1.3.1, 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 21.1.3.1, p6 from

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

to

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.]