Details
[Home]
Issue of the Implementation # S0770
Brief
Behaviour of basic_string
Detailed Description
The description of basic_string
int compare(size_type pos1, size_type n1, const basic_string
Returns:
basic_string
As it is also stated in the same section of the standard,
int compare(const basic_string
uses char_traits
However, on IA64 systems, the return value of __builtin_memcmp() depends not only on the values of its arguments.
This results in the situations when, in some cases (see the example below), compare(pos1, n1, str) returns 32, while basic_string
Problem location(s) in the standard
Linux Standard Base C++ Specification 3.2, Chapter 9. Libraries, 9.1. Interfaces for libstdcxx that refers ISO/IEC 14882: 2003 Programming languages --C++, section 21.3.6.8
Example
#include <string>
#include <cstdio>
#define CHAR_T char
#define STR_LEFT "The quick brown foxy"
#define STR_RIGHT "e quick brown Fox"
#define POS_VALUE 2
#define N_VALUE str_src.size() - 3
using namespace std;
int
main(int argc, char* argv[])
{
basic_string<CHAR_T> str_src(STR_LEFT);
basic_string<CHAR_T> str(STR_RIGHT);
size_t pos = POS_VALUE;
size_t n = N_VALUE;
basic_string<CHAR_T> str1(str_src, pos, n);
int ret_mustbe = str1.compare(str);
int ret = str_src.compare(pos, n, str);
printf("The function should have returned %d, it returned %d\n",
ret_mustbe, ret);
return 0;
}
Component
libstdc++
Environment
Architectures
IA64
[Home]