c++/8631: bug in typecasting the return value of a function

gkmohan@ece.arizona.edu gkmohan@ece.arizona.edu
Mon Nov 25 08:46:00 GMT 2002


>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:



More information about the Gcc-prs mailing list