Possible bug in std::string::rfind

This may be a bug in std::string::rfind on linux (lattest version of Debian). I run the following program:

#include <iostream>
#include <string>

int main (int argc, char * argv []) {

std::string str ("ÅÄÖ");

size_t index = str.rfind ("Å",0);

bool found = index < str.size ();

std::cout << found << std::endl;

return 0;
}

The character Å should not be found because the second parameter (pos) to rfind is 0. The documentation says that only characters before pos are searched. If I change the strings to be ascii only (0x00 - 0x7f) then the program works as documented. Is there anybody else that have noticed this behaviour? Thanks.
I've found the same behaviour on Windows using islower/isupper/isascii or similar while also using characters in the range 0x80-0xff.

Maybe the standard doesn't like them, i'd try to stick with unicode, try std::wstring and std::wcout (remember to change from "Text" to L"Text").
The documentation on this site is wrong. This is what the standard says.

§21.4.7.3 basic_string::rfind
size_type rfind(const charT* s, size_type pos = npos) const ;
Requires: s points to an array of at least traits::length(s) + 1 elements of charT.
Returns: rfind(basic_string(s), pos).

size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Effects: Determines the highest position xpos, if possible, such that both of the following conditions obtain:
- xpos <= pos and xpos + str.size() <= size();
- traits::eq(at(xpos+I), str.at(I)) for all elements I of the string controlled by str.
Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

xpos <= pos

:(
Topic archived. No new replies allowed.