Bug 26030 - C-style casts and function-style casts
Summary: C-style casts and function-style casts
Status: RESOLVED DUPLICATE of bug 10818
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-30 13:11 UTC by Wolfgang Roehrl
Modified: 2006-01-30 13:52 UTC (History)
4 users (show)

See Also:
Host: i386-pc-mingw32
Target: powerpc-wrs-vxworks
Build: sparc-sun-solaris2.5.1
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Roehrl 2006-01-30 13:11:24 UTC
Dear all,

I would like to post a bug report for the GNU C/C++ compiler 3.3-e500.

We use the compiler to generate code for a PowerPC processor.

Used invokation line for the GNU C++ compiler:

ccppc -c -x c++ -ansi -Wall -Werror -mcpu=8540 -fverbose-asm -mbig
      -fmerge-templates -mmultiple -mno-string -mstrict-align -O3
      -fno-exceptions -fno-rtti -fno-builtin-printf
      -I<different include paths>
      -D<differen #define's>
      X.CPP -oX.O


// file X.CPP

void f (int);

typedef int* I;

I f0 () { return static_cast<I>(f); }         <--- line 5

I f1 () { return reinterpret_cast<I>(f); }    <--- line 7

I f2 () { return (I)f; }         // cast notation

I f3 () { return I(f); }         // functional notation


The compiler gives the following error messages:
X.CPP: In function `int* f0()':
X.CPP:5: error: invalid static_cast from type `void ()(int)' to type `int*'
X.CPP: In function `int* f1()':
X.CPP:7: error: ISO C++ forbids casting between pointer-to-function and 
   pointer-to-object

I think the compiler should also reject the casts in f2() and f3():
- 5.4/5 states that the cast notation of explicit conversion performs only
  the conversions of a const_cast<>, of a static_cast<>, of reinterpret_cast<>
  and of certain combinations of those casts.
- 5.2.3/1 says that cast in f3() is equivalent to the cast in f2().

Kind regards
W. Roehrl
Comment 1 Andrew Pinski 2006-01-30 13:52:01 UTC
This is a dup of bug 10818.  Note DR 195 is related to this case.

*** This bug has been marked as a duplicate of 10818 ***