Bug 149098 - bogus function declaration conflict in C++
bogus function declaration conflict in C++
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
rawhide
All Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks: 149820
  Show dependency treegraph
 
Reported: 2005-02-18 12:50 EST by Tom Lane
Modified: 2013-07-02 23:03 EDT (History)
3 users (show)

See Also:
Fixed In Version: 4.0.0-0.32
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-03-10 04:20:41 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Tom Lane 2005-02-18 12:50:51 EST
Description of problem:
$ cat tgl.c
extern "C" void std::exit (int) throw (); using std::exit;
#include <stdlib.h>
$ g++ -c tgl.c
/usr/include/stdlib.h:644: error: `void exit(int)' conflicts with
previous using declaration `void std::exit(int)'
/usr/include/stdlib.h:644: error: `void exit(int)' conflicts with used
function
tgl.c:1: error: `void std::exit(int)' previously declared here

I might have thought this was ok, except (a) if I include stdlib.h
first then g++ accepts this, and (b) g++ 3.4.2 accepts either order.

Version-Release number of selected component (if applicable):
gcc-c++-3.4.3-19

How reproducible:
100%

Steps to Reproduce:
1.  See above
2.
3.
  
Actual results:
Failure depends on declaration ordering.

Expected results:
No failure ... or consistent failure.  Your choice.

Additional info:
This breaks most autoconf c++ tests that involve stdlib.h, because
autoconf is cavalier about which order the lines appear in; it tests
for the right way to declare exit() in the order that works, but then
puts the declaration ahead of stdlib.h when it counts.  In particular
I'm dead in the water with respect to rebuilding mysql in rawhide, so
I'd appreciate a fix ASAP.
Comment 1 Tom Lane 2005-02-18 15:29:37 EST
I forgot to mention that the same thing is happening in gcc4; or at
least, the test build Karsten did yesterday showed mysql failing in
the same way as I now see in rawhide.
Comment 2 Jakub Jelinek 2005-02-19 18:17:14 EST
Simplified into:
extern "C" void exit (int) throw ();
extern "C" void std::exit (int) throw (); using std::exit;
which works and
extern "C" void std::exit (int) throw (); using std::exit;
extern "C" void exit (int) throw ();
which doesn't in neither g++4 nor quite recent 3.4.3-RH (works with
20050113 but doesn't with 20050209.
Don't know whether that is a bug or mandated behaviour by the standard though.
Comment 3 Tom Lane 2005-02-20 00:58:31 EST
One would like to think that the standard is better designed than that :-(

A possible solution if it's determined that gcc is actually operating as designed is to hack 
up autoconf so that it always emits the explicit declaration before including stdlib.h.  If 
you think this will take awhile to resolve then I shall go bother whoever owns autoconf.
Comment 4 Alexandre Oliva 2005-02-21 23:06:40 EST
Per the ISO C++ 90 Standard, both cases should be errors, from 7.3.3:

11. If a function declaration in namespace scope or block scope has the same
name and the same parameter types as a function introduced by a
using-declaration, the program is ill-formed.

An example follows in which a function is declared after a using decl, noting
that it's ill-formed.  It's not entirely clear that having the using decl after
the function decl should trigger an error as well, although it appears to be the
intent, especially given the discussion regarding DR101:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#101

The resolution is that extern "C" functions can have multiple such declarations,
so we should accept, and not reject, both cases.

I'll try to cobble up a patch to get the same behavior regardless of the
relative location of the using declaration and the possibly-conflicting function
definition, without rejecting possibly-conflicting using declarations too early.
Comment 5 Tom Lane 2005-03-01 01:36:04 EST
You probably know that this is still broken in gcc 4.0.0-0.30, which means I'm still dead in 
the water for rebuilding mysql.
Comment 6 Jakub Jelinek 2005-03-10 04:20:41 EST
Should be fixed in gcc-4.0.0-0.32.
Comment 10 Tim Powers 2005-06-09 06:57:34 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2005-257.html

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