Bug 52565 - Bogus printf macro in /usr/include/bits/stdio.h
Bogus printf macro in /usr/include/bits/stdio.h
Product: Red Hat Public Beta
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2001-08-25 04:48 EDT by jay
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-08-25 04:57:31 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description jay 2001-08-25 04:48:34 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2 i586; en-US; 0.7) Gecko/20010316

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

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

How reproducible:

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.

Additional info:

Defining that macro wasn't a good idea.

I've marked this a severity: high becuase this makes valid programs fail to
compile, and it is insane to promote the software to full-release knowing
that it will break working software.
Comment 1 jay 2001-08-25 04:55:35 EDT
otoh this is really the fault of glibc rather than gcc3...
Comment 2 jay 2001-08-25 04:57:27 EDT
The offending macro is

# if __GNUC_PREREQ (2,97)
#  define printf(fmt, args...) fprintf (stdout, fmt, ##args)
# endif

Comment 3 Jakub Jelinek 2001-08-27 06:59:48 EDT
This macro was removed in glibc-2.2.4-1 (as gcc 3.0 can optimize printf
internally too).

Note You need to log in before you can comment on or make changes to this bug.