C++ Issue with const char * on strchr

Jakub Jelinek jakub at redhat.com
Tue Mar 10 20:52:35 UTC 2009


On Tue, Mar 10, 2009 at 09:42:24PM +0100, Jochen Schmitt wrote:
> Because this issue occurs only on gcc-4.4, I want to ask: is this
> a bug or a feature?

Feature.  ISO C++ mandates that std::strchr is overloaded:
char *strchr (char *, int);
const char *strchr (const char *, int);
and similarly for a whole bunch of other {str,mem,wcs}*
functions that return the first argument either unmodified or
with some offset added to it.  While the standard just talks about
std namespace and <cstring>/<cwchar> headers, gcc 4.4+ with glibc 2.10+
does that also in <string.h>/<wchar.h> for C++ (not doing it would lead to
different behaviour between
#include <string.h>
#include <cstring>
and
#include <cstring>
#include <string.h>
) and does that also for a bunch of GNU extensions where the overloading
makes sense.  The overloads make sense, these function no longer cast
away constness of pointed types, if you pass a char *, you get char *
back, if you pass const char *, you get const char * back.

	Jakub




More information about the fedora-devel-list mailing list