This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5133: Problems with toupper
- From: Martin Sebor <sebor at roguewave dot com>
- To: paolo at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 17 Dec 2001 01:46:01 -0000
- Subject: Re: libstdc++/5133: Problems with toupper
- Reply-to: Martin Sebor <sebor at roguewave dot com>
The following reply was made to PR libstdc++/5133; it has been noted by GNATS.
From: Martin Sebor <sebor@roguewave.com>
To: gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: libstdc++/5133: Problems with toupper
Date: Sun, 16 Dec 2001 18:54:22 -0700
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5133
None of the programs in this PR is well-formed for at least two reasons:
1. The first two refer to ::tolower or tolower without either first
#including <ctype.h>, or #including <cctype> *and* bringing
std::tolower into the global namespace via a using declaration
or directive.
2. The four-argument overload of std::transform() is a template
that expects a unary function [object] as its last argument,
i.e., a class type that defines operator() or a one argument
function with extern "C++" linkage. None of the two overloads
of std::tolower is likely to be such a function (the unary
version that's intended to be used is likely to have an extern
"C" linkage since it's a C library function). In fact, they are
known to be extern "C" in glibc on Linux, the reported platform.
Paolo's suggested change suffers from a variant of 1, except that it
doesn't qualify the name at all. It has the same problem as 2. IMO,
there are two reasons why this example compiles with gcc: one of the
headers inadvertently introduces the unary function tolower into the
global namespace, and the compiler fails to diagnose the incompatibility
of an extern "C" function with a pointer to an extern "C++" function.
The short story is that you cannot portably pass a function declared
in one of the C++ C library headers (such as <cctype> or the deprecated
<ctype.h>) as a template argument to a function template, since the
linkage of the latter requires that that the argument have C++ linkage
which is not guaranteed by the C++ Standard. For this reason, the
example is Jossutis' book is unportable and ill-formed on all platforms
I'm familiar with.
Regards
Martin