This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/5133: Problems with toupper




On 16 Dec 2001 paolo@gcc.gnu.org wrote:

> Synopsis: Problems with toupper
> 
> Responsible-Changed-From-To: unassigned->paolo
> Responsible-Changed-By: paolo
> Responsible-Changed-When: Sun Dec 16 13:53:55 2001
> Responsible-Changed-Why:
>     Taking care of this.
> State-Changed-From-To: open->feedback
> State-Changed-By: paolo
> State-Changed-When: Sun Dec 16 13:53:55 2001
> State-Changed-Why:
>     Hi Peter,
>     
>     in Josuttis, pp. 499 and 718 I find an explanation of what
>     is happening with your testcase. In a nutshell, tolower and
>     toupper are old C functions (you may use them through
>     cctype) whereas std::toupper(c, loc) (and the corresponding
>     tolower) are global functions of the C++ locales.
>     Therefore, your testcase should be changed to:
>     
>     #include <string>
>     #include <iostream> 
>     #include <algorithm>
>     #include <cctype>
>     
>     int main()
>     {
>         std::string s("Hallo");
>         //std::transform (s.begin(), s.end(), s.begin(), std::tolower);
>         //std::transform (s.begin(), s.end(), s.begin(), ::tolower);
>         std::transform (s.begin(), s.end(), s.begin(), tolower);
>         std::cout << "lowered: " << s << std::endl;
>     }
>     
>     which indeed compiles and runs fine.
>     
>     Ok?
>     
>     Cheers,
>     Paolo.
>     
>      
> 
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5133
> 

It is IMHO not ok. If you consider the following source tl.C, a stripped
down version from string/iter1.C from Josuttis, cf. pages number
497--499. Also cf. page number 720. 

I believe that this source code is legal and according to Josuttis the
<c*> headers inject the corresponding <*.h> functions into the std
namespace. Therefore, I have no idea why this code, the call to std::tolower
is rejected. Additionally, why does the code compile if the iostream
header is removed?

Peter Schmid 


tl.C
#include <string>
#include <iostream> // does work, when this line is removed
#include <algorithm>
#include <cctype>

using namespace std;

int main()
{
    string s("Hallo");
    transform (s.begin(), s.end(), s.begin(), tolower);
    transform (s.begin(), s.end(), s.begin(), ::tolower);
}

g++ -o tl tl.C -W -Wall
tl.C: In function `int main()':
tl.C:11: no matching function for call to `transform(
   std::__normal_iterator<char*, std::basic_string<char, 
   std::char_traits<char>, std::allocator<char> > >, 
   std::__normal_iterator<char*, std::basic_string<char, 
   std::char_traits<char>, std::allocator<char> > >, 
   std::__normal_iterator<char*, std::basic_string<char, 
   std::char_traits<char>, std::allocator<char> > >, <unknown type>)'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]