From: Greg C. <gch...@sb...> - 2011-03-26 11:33:29
|
On 2011-03-26 02:17Z, K. Frank wrote: > > On Tue, Mar 22, 2011 at 9:53 AM, Greg Chicares <gch...@sb...> wrote: >> >> std::string s("uvw"); >> std::string s3b = dynamic_cast<std::stringstream&>(std::stringstream() << s).str(); >> std::cout << "expecting uvw: " << s3b << std::endl; >> >> That succeeds with Comeau (but prints the pointer address), but fails >> with MinGW gcc-3.4.5: >> no match for 'operator<<' in 'stringstream(std::operator|( _S_out, _S_in)) << s' >> and 'stringstream(std::operator|( _S_out, _S_in))'... > > I was playing around with this test case (inserting a std::string), > because, according to my current understanding, it should fail > to compile, as it does with mingw. Yes, I think so, too. The candidate (C++2003 21.3.7.9/4) is: template<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const basic_string<charT,traits,Allocator>& str); which is a free function in <string>. Its first argument is a non-const reference, which can't be bound to a temporary. > I tried it with the Comeau online compiler (It doesn't actually > build the final executable, so you can't run it.), and it fails to > compile with an error analogous to that reported by mingw: > > "ComeauTest.c", line 27: error: no operator "<<" matches these operands > operand types are: std::stringstream << std::string > std::string s7 = > dynamic_cast<std::stringstream&>(std::stringstream() << s).str(); > > (The online compiler announces itself as "Comeau C/C++ 4.3.10.1".) > > That is, I'm failing to reproduce with the online compiler your > Comeau result. Any thoughts? Abbreviated testcase: #include <iostream> #include <ostream> #include <sstream> #include <string> int main() { std::string s("uvw"); std::string s3b = dynamic_cast<std::stringstream&> ((std::stringstream()) << s).str(); std::cout << "expecting uvw: " << s3b << std::endl; } It compiles and links here: /home/Arktos/tmp[0]$export COMO_MIN_INCLUDE=/opt/lmi/como/mingw_for_como/include /home/Arktos/tmp[0]$PATH=/opt/lmi/como/bin:/opt/lmi/como/mingw_for_como/bin:/usr /bin:/bin:/usr/sbin:/sbin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygd rive/c/WINDOWS/System32/Wbem /home/Arktos/tmp[0]$como stringstream_cast_como.cpp Comeau C/C++ 4.3.10.1 (May 7 2008 09:22:38) for MS_WINDOWS_x86_Beta1 Copyright 1988-2008 Comeau Computing. All rights reserved. MODE:non-strict warnings MinGW C++ noC++0x_extensions and prints: /home/Arktos/tmp[0]$./aout expecting uvw: uvw However, pasting it here: http://www.comeaucomputing.com/tryitout/ I cannot find any combination of options that prevents the error we expect. The compilers aren't quite identical: Comeau C/C++ 4.3.10.1 (May 7 2008 09:22:38) [my local copy] Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) [online] but it's hard to believe that different builds of the same version of an EDG compiler would change this fundamental behavior. Wait...even with "Compile in relaxed mode", the online compiler gives an error; but if I add '--a' for strict mode locally, then I do get the expected error: /home/Arktos/tmp[0]$como --no_microsoft_bugs --a stringstream_cast_como.cpp Comeau C/C++ 4.3.10.1 (May 7 2008 09:22:38) for MS_WINDOWS_x86_Beta1 Copyright 1988-2008 Comeau Computing. All rights reserved. MODE:strict warnings [MinGW] C++ noC++0x_extensions "stringstream_cast_como.cpp", line 10: error: no operator "<<" matches these operands operand types are: std::stringstream << std::string ((std::stringstream()) << s).str(); ^ I don't normally use strict mode because it's incompatible with <windows.h>, but it's appropriate for this testcase. |