Bug 52565 - Bogus printf macro in /usr/include/bits/stdio.h
Summary: Bogus printf macro in /usr/include/bits/stdio.h
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Public Beta
Classification: Retired
Component: glibc
Version: roswell
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-08-25 08:48 UTC by jay
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-08-25 08:57:31 UTC
Embargoed:


Attachments (Terms of Use)

Description jay 2001-08-25 08:48:34 UTC
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
printf.

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.

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 08:55:35 UTC
otoh this is really the fault of glibc rather than gcc3...

Comment 2 jay 2001-08-25 08:57:27 UTC
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 10:59:48 UTC
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.