Title
char_traits::lt(), compare(), and memcmp()
Status
cd1
Section
[char.traits.specializations.char]
Submitter
Martin Sebor

Created on 2004-06-28.00:00:00 last changed 163 months ago

Messages

Date: 2010-10-21.18:28:33

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

Date: 2010-10-21.18:28:33

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.

Date: 2004-06-28.00:00:00

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2747
2010-10-21 18:28:33adminsetmessages: + msg2746
2004-06-28 00:00:00admincreate