bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in bits/stdio.h when used with GCC-3


From: James Youngman
Subject: Bug in bits/stdio.h when used with GCC-3
Date: 25 Aug 2001 10:02:57 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Description of problem:

When compiling programs with optimisation, GCC defines the
__USE_EXTERN_INLINES macro.  The /usr/include/bits/stdio.h header
#defines a macro for printf in this case.  However, while this is
probably fine for C, it breaks C++ programs where objects can have
member functions called printf.  This macro is also not defined if the
GCC version is earlier than 2.97.   Here is the offending code :-


#ifdef __USE_EXTERN_INLINES
/* Since version 2.97 GCC knows about `fprintf' and can optimize certain
   cases.  Help gcc to optimize more code by mapping `printf' to the known
   `fprintf' function.  Unfortunately we have to use a macro.  */
# if __GNUC_PREREQ (2,97)
#  define printf(fmt, args...) fprintf (stdout, fmt, ##args)
# endif





Version-Release number of selected component (if applicable):


How reproducible: Always

Steps to Reproduce:
Compile the following program with "g++3 -O2"

#include <stdio.h>

struct foo 
{
        int val;
        foo() : val(0) { }
        int printf(const char *fmt, ...) { return 0; }
};

int main (int argc, char *argv[])
{
        return 0;
}


This will fail because the "printf(.." gets turned into
"fprintf(stdout,..." which is not valid for a function defintion.

Note that becuase of the fact that the macro is only defined if
__USE_EXTERN_INLINES is defined by the compiler, this bug will NOT
occur if you compile without optimisation.  It also goes away if you
change the name of the member function (unfortunately I have about
1000 of them).

Actual Results:  testit2.cc:7: parse error before `char'


Expected Results:  Program should compile without error. 

-- 
James Youngman
Manchester, UK.  +44 161 226 7339
PGP (GPG) key ID for <address@hidden> is 64A95EE5 (F1B83152).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]