public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8631: bug in typecasting the return value of a function
@ 2002-11-25 15:13 bangerth
0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2002-11-25 15:13 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, gkmohan, nobody
Synopsis: bug in typecasting the return value of a function
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Tue Nov 19 07:01:18 2002
State-Changed-Why:
User error. You are trying nonsense and getting nonsense. No
surprise.
Had you used a static_cast instead of the C-style cast like
this:
f2( static_cast<CAST (*)(int)>(&f1), 4 );
then the compiler would tell you quite correctly:
tmp/g> /home/bangerth/bin/gcc-3.3x-pre/bin/c++ x.cc
x.cc: In function `int main()':
x.cc:18: error: invalid static_cast from type `int (*)(int)' to type `
std::complex<double> (*)(int)'
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8631
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++/8631: bug in typecasting the return value of a function
@ 2002-11-25 8:46 gkmohan
0 siblings, 0 replies; 2+ messages in thread
From: gkmohan @ 2002-11-25 8:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 8631
>Category: c++
>Synopsis: bug in typecasting the return value of a function
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Nov 18 18:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: gkmohan@ece.arizona.edu
>Release: unknown-1.0
>Organization:
>Environment:
>Description:
typecasting a function pointer to return different value seg faults or returns nonsense (depending on the version)
this is what g++ -v returns
-----------------------------------------------------
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-85)
-----------------------------------------------------
--file test.cc--
#include <iostream.h>
#include <complex.h>
#define CAST complex<double>
int f1( int x )
{
return x;
}
void f2( CAST (*f)(int), int x )
{
cout << (*f)(x);
}
main()
{
f2( (CAST (*)(int)) &f1, 4 );
}
>How-To-Repeat:
g++ -o test test.cc
./test
>Fix:
:-< none
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-19 15:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-25 15:13 c++/8631: bug in typecasting the return value of a function bangerth
-- strict thread matches above, loose matches on Subject: below --
2002-11-25 8:46 gkmohan
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).