[PATCH] Fix PR c++/14791

Roger Sayle roger@eyesopen.com
Mon Apr 26 00:59:00 GMT 2004


On Sun, 25 Apr 2004, Kaveh R. Ghazi wrote:
>  > I notice that you still haven't committed your patch from the 2nd
>  > April to add a BT_FILEPTR builtin type, so that the C++ front-end can
>  > recognize fprintf and friends as GCC builtin functions.
>  >
>  > http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00132.html
>
> Q: does Jakub's approach work when `FILE' is a macro resolving to
> something else like struct __iob or what not?

It doesn't look like it does.  Whilst such macros are obviously acceptable
for C's stdio, I'm not sure if ::FILE and std::FILE have to exist as
real types in C++.  This would also affect name mangling of functions
taking a FILE* argument.  Perhaps a language lawyer would like to
provide an opinion.

A more elaborate form of Jakub's patch would be to deduce the type
of "FILE *" from it's context.  i.e. the first builtin stdio function
whose prototype matches GCC's expectations, with the exception of
the "FILE*" parameter, gets to define BT_FILEPTR.  We then assume the
prototype is valid, and copy the "FILE*" arguments type into TI_FILEPTR.
All subsequent builtin prototypes then have to match this type.

There's also the potential fixincludes workaround/hack:

#ifdef FILE
typedef FILE
#undef FILE
FILE;
#endif


Jakub's patch is still a constructive step in the right direction.  We
improve from failing everywhere to just failing on platforms where FILE
is a macro.  Unless, of course, someone proposes a better solution for
review :>

Roger
--



More information about the Gcc-patches mailing list