Bug 149098 - bogus function declaration conflict in C++
Summary: bogus function declaration conflict in C++
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: All
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 149820
TreeView+ depends on / blocked
 
Reported: 2005-02-18 17:50 UTC by Tom Lane
Modified: 2013-07-03 03:03 UTC (History)
3 users (show)

Fixed In Version: 4.0.0-0.32
Clone Of:
Environment:
Last Closed: 2005-03-10 09:20:41 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2005:257 0 normal SHIPPED_LIVE gcc bug fix update 2005-06-09 04:00:00 UTC

Description Tom Lane 2005-02-18 17:50:51 UTC
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 20:29:37 UTC
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 23:17:14 UTC
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 05:58:31 UTC
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-22 04:06:40 UTC
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 06:36:04 UTC
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 09:20:41 UTC
Should be fixed in gcc-4.0.0-0.32.

Comment 10 Tim Powers 2005-06-09 10:57:34 UTC
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.