puzzling error from GCC 3.4.4

D

drn

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;

Thanks in advance for any help !
Best Regards, Dave

The correct match below is:
parsTool.hpp:165: note: std::istream& operator>>(std::istream&,
NavLatLongPoint&)

$ gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/
configure --ver
bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/
lib --libe
xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --
enable-langu
ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-
gettext --
enable-version-specific-runtime-libs --without-x --enable-libgcj --
disable-java-
awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --
enable-thre
ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-
sjlj-exceptio
ns --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

Error output:

airparse.cpp: In function `int main(int, char**)':
airparse.cpp:680: error: no match for 'operator>>' in
'istrstream((*(argv + 8u))) >> mapReferencePoint'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:87:
note: candidates are: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>::eek:perator>>(std::basic_istream<_CharT, _Traits>&(*)
(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:93:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(std::basic_ios<_CharT, _Traits>&(*)
(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:102:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:111:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(bool&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:133:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(short int&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:164:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(short unsigned int&) [with _CharT = char, _Traits
= std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:186:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(int&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:217:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(unsigned int&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:239:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(long int&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:261:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(long unsigned int&) [with _CharT = char, _Traits
= std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:284:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(long long int&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:306:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(long long unsigned int&) [with _CharT = char,
_Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:329:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(float&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:351:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(double&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:373:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(long double&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:395:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(void*&) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/istream.tcc:417:
note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
_Traits>::eek:perator>>(std::basic_streambuf<_CharT, _Traits>*) [with
_CharT = char, _Traits = std::char_traits<char>]
parsTool.hpp:131: note: std::istream& operator>>(std::istream&,
LatitudeT&)
parsTool.hpp:136: note: std::istream& operator>>(std::istream&,
LongitudeT&)
parsTool.hpp:165: note: std::istream& operator>>(std::istream&,
NavLatLongPoint&)
airparse.cpp:174: note: std::istream& operator>>(std::istream&,
TNPAltitude&)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iomanip:253: note:
std::basic_istream<_CharT, _Traits>&
std::eek:perator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iomanip:219: note:
std::basic_istream<_CharT, _Traits>&
std::eek:perator>>(std::basic_istream<_CharT, _Traits>&,
std::_Setprecision) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iomanip:143: note:
std::basic_istream<_CharT, _Traits>&
std::eek:perator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iomanip:108: note:
std::basic_istream<_CharT, _Traits>&
std::eek:perator>>(std::basic_istream<_CharT, _Traits>&,
std::_Setiosflags) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iomanip:74: note:
std::basic_istream<_CharT, _Traits>&
std::eek:perator>>(std::basic_istream<_CharT, _Traits>&,
std::_Resetiosflags) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/istream:692: note:
std::basic_istream<char, _Traits>&
std::eek:perator>>(std::basic_istream<char, _Traits>&, signed char*)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/istream:687: note:
std::basic_istream<char, _Traits>&
std::eek:perator>>(std::basic_istream<char, _Traits>&, unsigned char*)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/istream:651: note:
std::basic_istream<char, _Traits>&
std::eek:perator>>(std::basic_istream<char, _Traits>&, signed char&)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/istream:646: note:
std::basic_istream<char, _Traits>&
std::eek:perator>>(std::basic_istream<char, _Traits>&, unsigned char&)
[with _Traits = std::char_traits<char>]
 
O

Ole Nielsby

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;

C++ has a restriction that says, non-const references cannot bind
to temporaries, though many compilers allow it. I think that's what
happens here.
 
G

Gianni Mariani

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;

re:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ )

a) The standard name is "std::istringstream".

b) The following code compiles.
#include <sstream>
#include <iostream>

int main( int argc, char ** argv)
{
int i;

std::istringstream("10") >> i;
}

So it may be an issue with how you defined your operator >>.

I ran into a number of issues when I placed the operator >> in a
namespace other than "std". This may be a bug with gcc 3.4.4 as I don't
recall running into it with the latest gcc compilers.

What does you declaration for operator>> look like ? Can you give us a
chunk-o-compilable-code ?
 
O

Old Wolf

istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ )

a) The standard name is "std::istringstream".

istrstream and istringstream are different standard classes.
See D.7.2 [depr.istrstream] in the standard.
 
J

James Kanze

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;
re:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ )
a) The standard name is "std::istringstream".

Both istrstream and istringstream are defined in the standard.
istrstream has its uses, although I'd probably prefer
istringstream here.
b) The following code compiles.
#include <sstream>
#include <iostream>
int main( int argc, char ** argv)
{
int i;

std::istringstream("10") >> i;
}
So it may be an issue with how you defined your operator >>.

Or how the standard requires it to be defined:

int main()
{
std::string s ;
std::istringstream( "10" ) >> s ;
}

doesn't compile. In general, if the operator>> is a member of
istream, it compiles, if the operator>> isn't (and that includes
the operators for all user defined types), it doesn't. (For
output, the behavior is even worse: if there is an implicit
conversion to a type whose << is a member, it is used, and you
output this type.)

The problem is binding a temporary (the istringstream) to a
non-const reference (vs. calling a non-const member function on
a temporary). This is a well known anomaly in the way iostream
works.
I ran into a number of issues when I placed the operator >> in
a namespace other than "std".

This depends on what you are outputting, and how you use the
operator. The classic problem here is inputting or outputting a
"standard" type (e.g. std::vector<int>) through a template (e.g.
std::istream_iterator or std::eek:stream_iterator); when
instantiating a template, the compiler only uses argument
dependent lookup for dependent names, so you must have something
in the type you're outputting which uses the namespace where
you've put the operator>>.

The simple answer for this is: don't do it. But while it is the
only correct answer for production code, it is often very
convenient to define an output (or input) operator for something
like std::vector<int> in a small test program. Defining such an
operator yourself in std is formally undefined behavior, but in
practice, for small, throw away test programs, I'll do it.
 
D

drn

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;

re:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ )

a) The standard name is "std::istringstream".

b) The following code compiles.
#include <sstream>
#include <iostream>

int main( int argc, char ** argv)
{
int i;

std::istringstream("10") >> i;

}

So it may be an issue with how you defined your operator >>.

I ran into a number of issues when I placed the operator >> in a
namespace other than "std". This may be a bug with gcc 3.4.4 as I don't
recall running into it with the latest gcc compilers.

What does you declaration for operator>> look like ? Can you give us a
chunk-o-compilable-code ?

Hi Gianni - This code uses istrstream specifically.
Yes its deprecated, but as I said in my post this is
port of legacy code...

The >> operator here is used to parse a string
into an application data type. The operator is a
non-class definition relating istrstream to
the app's type.

Thanks though,
Best Regards, Dave
 
D

drn

I'm porting some legacy code from BC++5.01 to GCC C++.
I'm a bit baffled - why does GCC produce the errors below using a
temporary in the line:
istrstream( argv[2] /*"49:59.067 N 011:38.317 E"*/ ) >>
mapReferencePoint;
No complaints when its split into two lines as follows:
istrstream is( argv[2] /*"49:59.067 N 011:38.317 E"*/ );
is >> mapReferencePoint;

C++ has a restriction that says, non-const references cannot bind
to temporaries, though many compilers allow it. I think that's what
happens here.

Thanks Ole - That seems to be the problem,
Best Regards, Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top