public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
@ 2003-05-10 17:46 Dave Brondsema
0 siblings, 0 replies; 5+ messages in thread
From: Dave Brondsema @ 2003-05-10 17:46 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/8567; it has been noted by GNATS.
From: Dave Brondsema <brondsem@yahoo.com>
To: gcc-gnats@gcc.gnu.org, jstanek@vrac.iastate.edu, gcc-bugs@gcc.gnu.org,
nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org, jstanek@iastate.edu
Cc:
Subject: Re: c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
Date: Sat, 10 May 2003 10:36:08 -0700 (PDT)
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8567
The following 2 samples are based on the solutions given, but
still fail to compile. I'm using g++ (GCC) 3.2.2 on i686
#include <iostream>
class BlackHole{};
template <typename T> BlackHole& operator<<(BlackHole& bh, const
T& dummy);
template <typename T> BlackHole& operator<<(BlackHole& bh, T&
(*dummy)(T&));
int main() {
BlackHole bh;
bh << std::endl;
}
=======
test.cpp: In function `int main()':
test.cpp:11: no match for `BlackHole& << <unknown type>'
operator
=======
=======
#include <iostream>
class BlackHole{};
template <typename T> BlackHole& operator<<(BlackHole& bh, const
T& dummy);
(*dummy)(T&));
BlackHole& operator<<(BlackHole& bh, int& (*dummy)(int&));
int main() {
BlackHole bh;
bh << std::endl;
}
=======
test.cpp: In function `int main()':
test.cpp:11: no match for `BlackHole& << <unknown type>'
operator
test.cpp:7: candidates are: BlackHole& operator<<(BlackHole&,
int&(*)(int&))
=====
Dave Brondsema
dave@brondsema.net
http://www.brondsema.net - personal
http://www.splike.com - programming
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
@ 2002-11-21 7:18 Wolfgang Bangerth
0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bangerth @ 2002-11-21 7:18 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/8567; it has been noted by GNATS.
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: Jason Stanek <jstanek@iastate.edu>
Cc: gcc-bugs@gcc.gnu.org, <jstanek@vrac.iastate.edu>, <gcc-gnats@gcc.gnu.org>
Subject: Re: c++/8567: std::endl is of unknown type when overloading operator<<
(repeat in case attachment didnt work)
Date: Fri, 15 Nov 2002 10:06:47 -0600 (CST)
> Isnt there a way to specify a default template type?
>
> So instead of declaring endl as a pure template, it has a default type in
> the case that you dont specify one.
>
> Something like this:
>
> namespace std {
> template <typename T=int> T& endl (T&);
> };
Default template arguments are only possible for classes, not for function
templates.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
@ 2002-11-21 6:26 Jason Stanek
0 siblings, 0 replies; 5+ messages in thread
From: Jason Stanek @ 2002-11-21 6:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/8567; it has been noted by GNATS.
From: Jason Stanek <jstanek@iastate.edu>
To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
jstanek@iastate.edu, jstanek@vrac.iastate.edu, nobody@gcc.gnu.org,
gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: c++/8567: std::endl is of unknown type when overloading
operator<< (repeat in case attachment didnt work)
Date: Thu, 14 Nov 2002 21:13:20 -0600
Isnt there a way to specify a default template type?
So instead of declaring endl as a pure template, it has a default type in
the case that you dont specify one.
Something like this:
namespace std {
template <typename T=int> T& endl (T&);
};
-Jason
At 11:37 PM 11/14/2002 +0000, you wrote:
>Synopsis: std::endl is of unknown type when overloading operator<< (repeat
>in case attachment didnt work)
>
>State-Changed-From-To: open->closed
>State-Changed-By: bangerth
>State-Changed-When: Thu Nov 14 15:37:17 2002
>State-Changed-Why:
> Not a bug. Basically, it is this:
> ---------------------------------
> namespace std {
> template <typename T> T& endl (T&);
> };
>
> class BlackHole{};
>
> template <typename T> BlackHole& operator<<(BlackHole& bh, const T&
> dummy);
> template <typename T> BlackHole& operator<<(BlackHole& bh, T&
> (*dummy)(T&));
>
> int main() {
> BlackHole bh;
> bh << std::endl;
> }
> -------------------------------
> Since there is no unambiguous function std::endl, the
> compiler cannot know which one to take as argument, so
> you have to disambiguate the situation by passing it the
> exact template argument list. Alternatively, you can give
> an overloaded non-template op<<; in this example, this
> would do:
> BlackHole& operator<<(BlackHole& bh, int& (*dummy)(int&));
> Then std::endl<int> would be taken.
>
> W.
>
>http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8567
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
@ 2002-11-21 4:17 bangerth
0 siblings, 0 replies; 5+ messages in thread
From: bangerth @ 2002-11-21 4:17 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, jstanek, jstanek, nobody
Synopsis: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Thu Nov 14 15:37:17 2002
State-Changed-Why:
Not a bug. Basically, it is this:
---------------------------------
namespace std {
template <typename T> T& endl (T&);
};
class BlackHole{};
template <typename T> BlackHole& operator<<(BlackHole& bh, const T& dummy);
template <typename T> BlackHole& operator<<(BlackHole& bh, T& (*dummy)(T&));
int main() {
BlackHole bh;
bh << std::endl;
}
-------------------------------
Since there is no unambiguous function std::endl, the
compiler cannot know which one to take as argument, so
you have to disambiguate the situation by passing it the
exact template argument list. Alternatively, you can give
an overloaded non-template op<<; in this example, this
would do:
BlackHole& operator<<(BlackHole& bh, int& (*dummy)(int&));
Then std::endl<int> would be taken.
W.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8567
^ permalink raw reply [flat|nested] 5+ messages in thread
* c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
@ 2002-11-20 4:46 jstanek
0 siblings, 0 replies; 5+ messages in thread
From: jstanek @ 2002-11-20 4:46 UTC (permalink / raw)
To: gcc-gnats; +Cc: jstanek
>Number: 8567
>Category: c++
>Synopsis: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: support
>Submitter-Id: net
>Arrival-Date: Wed Nov 13 13:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Jason Stanek
>Release: gcc-3.2
>Organization:
>Environment:
cruncher 110% uname -a
IRIX64 cruncher 6.5 07121149 IP27
cruncher 109% g++32 -v -save-temps Unknown.cpp
Reading specs from /home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/specs
Configured with: ../gcc-3.2-src/configure --prefix=/home/users/jstanek/gcc-3.2 --exec-prefix=/home/users/jstanek/gcc-3.2/irix
Thread model: single
gcc version 3.2
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -Dunix -Dmips -Dsgi -Dhost_mips -DMIPSEB -D_MIPSEB -DSYSTYPE_SVR4 -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix__ -D__mips__ -D__sgi__ -D__host_mips__ -D__MIPSEB__ -D_MIPSEB -D__SYSTYPE_SVR4__ -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix -D__mips -D__sgi -D__host_mips -D__MIPSEB -D__SYSTYPE_SVR4 -Asystem=unix -Asystem=svr4 -Acpu=mips -Amachine=sgi -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D__LANGUAGE_C_PLUS_PLUS -D_LANGUAGE_C_PLUS_PLUS -D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int -D__WCHAR_TYPE__=long int -D__WINT_TYPE__=long int -D__mips_fpr=64 -D__EXTENSIONS__ -D_SGI_SOURCE -D_MIPS_FPSET=32 -D_MIPS_ISA=_MIPS_ISA_MIPS3 -D_ABIN32=2 -D_MIPS_SIM=_ABIN32 -D_MIPS_SZINT=32 -D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32 -D_COMPILER_VERSION=601 -U__mips -D__mips=3 -D__mips64 Unknown.cpp Unknown.ii
GNU CPP version 3.2 (cpplib) [AL 1.1, MM 40] SGI running IRIX 6.x
ignoring nonexistent directory "/home/users/jstanek/gcc-3.2/irix/mips-sgi-irix6.5/include"
#include "..." search starts here:
#include <...> search starts here:
/home/users/jstanek/gcc-3.2/include/c++/3.2
/home/users/jstanek/gcc-3.2/include/c++/3.2/mips-sgi-irix6.5
/home/users/jstanek/gcc-3.2/include/c++/3.2/backward
/usr/local/include
/home/users/jstanek/gcc-3.2/include
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/include
/usr/include
End of search list.
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/cc1plus -fpreprocessed Unknown.ii -quiet -dumpbase Unknown.cpp -version -o Unknown.s
GNU CPP version 3.2 (cpplib) [AL 1.1, MM 40] SGI running IRIX 6.x
GNU C++ version 3.2 (mips-sgi-irix6.5)
compiled by GNU C version 3.2.
Unknown.cpp: In function `int main()':
Unknown.cpp:25: no match for `BlackHole& << <unknown type>' operator
>Description:
cruncher 109% g++32 -v -save-temps Unknown.cpp
Reading specs from /home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/specs
Configured with: ../gcc-3.2-src/configure --prefix=/home/users/jstanek/gcc-3.2 --exec-prefix=/home/users/jstanek/gcc-3.2/irix
Thread model: single
gcc version 3.2
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -Dunix -Dmips -Dsgi -Dhost_mips -DMIPSEB -D_MIPSEB -DSYSTYPE_SVR4 -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix__ -D__mips__ -D__sgi__ -D__host_mips__ -D__MIPSEB__ -D_MIPSEB -D__SYSTYPE_SVR4__ -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix -D__mips -D__sgi -D__host_mips -D__MIPSEB -D__SYSTYPE_SVR4 -Asystem=unix -Asystem=svr4 -Acpu=mips -Amachine=sgi -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D__LANGUAGE_C_PLUS_PLUS -D_LANGUAGE_C_PLUS_PLUS -D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int -D__WCHAR_TYPE__=long int -D__WINT_TYPE__=long int -D__mips_fpr=64 -D__EXTENSIONS__ -D_SGI_SOURCE -D_MIPS_FPSET=32 -D_MIPS_ISA=_MIPS_ISA_MIPS3 -D_ABIN32=2 -D_MIPS_SIM=_ABIN32 -D_MIPS_SZINT=32 -D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32 -D_COMPILER_VERSION=601 -U__mips -D__mips=3 -D__mips64 Unknown.cpp Unknown.ii
GNU CPP version 3.2 (cpplib) [AL 1.1, MM 40] SGI running IRIX 6.x
ignoring nonexistent directory "/home/users/jstanek/gcc-3.2/irix/mips-sgi-irix6.5/include"
#include "..." search starts here:
#include <...> search starts here:
/home/users/jstanek/gcc-3.2/include/c++/3.2
/home/users/jstanek/gcc-3.2/include/c++/3.2/mips-sgi-irix6.5
/home/users/jstanek/gcc-3.2/include/c++/3.2/backward
/usr/local/include
/home/users/jstanek/gcc-3.2/include
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/include
/usr/include
End of search list.
/home/users/jstanek/gcc-3.2/irix/lib/gcc-lib/mips-sgi-irix6.5/3.2/cc1plus -fpreprocessed Unknown.ii -quiet -dumpbase Unknown.cpp -version -o Unknown.s
GNU CPP version 3.2 (cpplib) [AL 1.1, MM 40] SGI running IRIX 6.x
GNU C++ version 3.2 (mips-sgi-irix6.5)
compiled by GNU C version 3.2.
Unknown.cpp: In function `int main()':
Unknown.cpp:25: no match for `BlackHole& << <unknown type>' operator
When overloading the operator<< for a class other than of type ostream, the compiler is unable to find the type of std::endl.
The compiler should be able to find the type of std::endl, since it should be a function pointer. This happens on irix g++3.2, irix g++3.0.4, linux g++3.2, and linux g++3.0.4 (probably all 3.0+ compilers).
Since I'm not sure the attachment was received correctly, I apologize, but I am sending the bug report again with the file text included here:
//////////////////////////////////////////////////////
#include <iostream>
//#define endl endl<char,std::char_traits<char> >
class BlackHole{};
template <typename T>
BlackHole& operator<<(BlackHole& bh, const T& dummy)
{
return bh;
}
template <typename T>
BlackHole& operator<<(BlackHole& bh, T& (*dummy)(T&))
{
return bh;
}
int main()
{
BlackHole bh;
std::cout << "hi" << std::endl;
std::endl(std::cout);
bh << std::endl;
return 0;
}
//////////////////////////////////////////////////////
>How-To-Repeat:
Compile the file using g++.
>Fix:
instead of using std::endl, use std::endl<char,char_traits<char> > or
#define endl endl<char,std::char_traits<char> >
Should I really have to do this? This seems really wordy and a waste of time. I would really appreciate it if someone let me know a better way to do this.
Thanks,
-Jason
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="Unknown.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Unknown.cpp"
I2luY2x1ZGUgPGlvc3RyZWFtPgoKLy8jZGVmaW5lIGVuZGwgZW5kbDxjaGFyLHN0ZDo6Y2hhcl90
cmFpdHM8Y2hhcj4gPgoKY2xhc3MgQmxhY2tIb2xle307Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4K
QmxhY2tIb2xlJiBvcGVyYXRvcjw8KEJsYWNrSG9sZSYgYmgsIGNvbnN0IFQmIGR1bW15KQp7CiAg
cmV0dXJuIGJoOwp9Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4KQmxhY2tIb2xlJiBvcGVyYXRvcjw8
KEJsYWNrSG9sZSYgYmgsIFQmICgqZHVtbXkpKFQmKSkKewogIHJldHVybiBiaDsKfQoKaW50IG1h
aW4oKQp7CiAgQmxhY2tIb2xlIGJoOwoKICBzdGQ6OmNvdXQgPDwgImhpIiA8PCBzdGQ6OmVuZGw7
CiAgc3RkOjplbmRsKHN0ZDo6Y291dCk7CgogIGJoIDw8IHN0ZDo6ZW5kbDsgIAogIAogIHJldHVy
biAwOwp9Cg==
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-05-10 17:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-10 17:46 c++/8567: std::endl is of unknown type when overloading operator<< (repeat in case attachment didnt work) Dave Brondsema
-- strict thread matches above, loose matches on Subject: below --
2002-11-21 7:18 Wolfgang Bangerth
2002-11-21 6:26 Jason Stanek
2002-11-21 4:17 bangerth
2002-11-20 4:46 jstanek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).