public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12629] New: name leaks
@ 2003-10-15 22:45 yujie dot wu at hec dot utah dot edu
  2003-10-15 22:49 ` [Bug c++/12629] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: yujie dot wu at hec dot utah dot edu @ 2003-10-15 22:45 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12629

           Summary: name leaks
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yujie dot wu at hec dot utah dot edu
                CC: gcc-bugs at gcc dot gnu dot org

The function name `exit' should stay in std namespace when <csdtlib> is
included. But not.

Try the following program to reproduce the error:

#include <cstdlib>
#include <cstdio>
 
 
void exit( int a = 0 )
{
   std::puts( "dddddddd" );
   std::exit( a );
}
 
 
int main()
{
   exit( 1 );
}

Correct program should print "ddddddddd" once. Erroneous program prints many
times because the statement "std::exit" actually calls the `exit' defined in the
global scope.

The problem exists in both 3.3.x and 3.4 snapshots.


Another name leak is `random' (only found on cygwin). This name seems to have
been used by gcc somewhere (<cstdlib>) and leaks into the global scope.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/12629] name leaks
  2003-10-15 22:45 [Bug c++/12629] New: name leaks yujie dot wu at hec dot utah dot edu
@ 2003-10-15 22:49 ` pinskia at gcc dot gnu dot org
  2003-10-18 12:27 ` gdr at integrable-solutions dot net
  2003-10-20 19:21 ` gdr at integrable-solutions dot net
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-15 22:49 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12629


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-15 22:49 -------
This is a dup of bug 6257.

*** This bug has been marked as a duplicate of 6257 ***


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/12629] name leaks
  2003-10-15 22:45 [Bug c++/12629] New: name leaks yujie dot wu at hec dot utah dot edu
  2003-10-15 22:49 ` [Bug c++/12629] " pinskia at gcc dot gnu dot org
@ 2003-10-18 12:27 ` gdr at integrable-solutions dot net
  2003-10-20 19:21 ` gdr at integrable-solutions dot net
  2 siblings, 0 replies; 4+ messages in thread
From: gdr at integrable-solutions dot net @ 2003-10-18 12:27 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12629



------- Additional Comments From gdr at integrable-solutions dot net  2003-10-18 11:32 -------
Subject: Re:  New: name leaks

"yujie dot wu at hec dot utah dot edu" <gcc-bugzilla@gcc.gnu.org> writes:

| Try the following program to reproduce the error:
| 
| #include <cstdlib>
| #include <cstdio>
|  
|  
| void exit( int a = 0 )
| {
|    std::puts( "dddddddd" );
|    std::exit( a );
| }

This program is invalid:  The reason is that the C funuction "exit"
may have a C linkage, in which case your definition invokes undefined
behaviour.  In fact, all C function in GNU C++ have C linkage.  

-- Gaby


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/12629] name leaks
  2003-10-15 22:45 [Bug c++/12629] New: name leaks yujie dot wu at hec dot utah dot edu
  2003-10-15 22:49 ` [Bug c++/12629] " pinskia at gcc dot gnu dot org
  2003-10-18 12:27 ` gdr at integrable-solutions dot net
@ 2003-10-20 19:21 ` gdr at integrable-solutions dot net
  2 siblings, 0 replies; 4+ messages in thread
From: gdr at integrable-solutions dot net @ 2003-10-20 19:21 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12629



------- Additional Comments From gdr at integrable-solutions dot net  2003-10-20 19:11 -------
Subject: Re:  name leaks

Yujie Wu <yujie.wu@hec.utah.edu> writes:

| Thanks for your comments. In fact, it is a VALID C++ program accroding
| to the C++ standard:  All C-library functions in C++ should be wrapped
| into `std' namespace rather than staying in the global namespace as in C.

The program is NOT valid.  Here is why:

17.4.3.1.3/4

  Each name from the Standard C library declared with external linkage
  is reserved to the implementation for use with extern "C" linkage,
  both in namespace std and in the global namespace. 

| Whatever linkages those function have is the business of the compiler,
| which should deal it in the way the standard says (if it wants to be a
| compliant compiler).

The issue is not that simple.  See above.  The reason is that if a
function is declared as having a C linkage then *all* declarations of
the same function in *any* namespace refer to the *same function*.
Therefore your definition of ::exit is ill-formed.  

-- Gaby


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-20 19:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-15 22:45 [Bug c++/12629] New: name leaks yujie dot wu at hec dot utah dot edu
2003-10-15 22:49 ` [Bug c++/12629] " pinskia at gcc dot gnu dot org
2003-10-18 12:27 ` gdr at integrable-solutions dot net
2003-10-20 19:21 ` gdr at integrable-solutions dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).