This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12401] G++ generates boguous weak definition of library routine
- From: "uddeborg at carmen dot se" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Jan 2004 16:57:07 -0000
- Subject: [Bug c++/12401] G++ generates boguous weak definition of library routine
- References: <20030925121817.12401.uddeborg@carmen.se>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From uddeborg at carmen dot se 2004-01-14 16:56 -------
I understand what you say about extern inline in C++. But note that my original
example did not include any explicit such definition. Also note that no weak
definition is generated if a file (translation unit) is compiled without
optimization. (Maybe to simplify debugging.) Let me give a slightly bigger
example to illustrate the problem:
Create a file e.cc which contains a use of atoi, and some object with a side
effect in the constructor:
#include <cstdlib>
#include <iostream>
int f() { return atoi <= 0; }
class sideeffect
{
public:
sideeffect() { std::cout << "Unwanted side effect." << std::endl; }
} s;
and a main program in f.cc which uses atoi:
#include <cstdlib>
#include <iostream>
int main() { std::cout << atoi("5") << std::endl; return 0; }
Now compile e.cc with optimization and put it in an archive library:
c++ -c -O e.cc
ar r libe.a e.o
Compile the main program without optimization, and link with this library:
c++ f.cc -o f libe.a
Running this will have the "unwanted side effect" printed out. I believe the
program itself meets all requirements in the C++ standard. The standard does
not go into such things as optimization flags. So if one wants to be picky I
guess one could argue the same set of flags should be applied to all translation
units.
But is this really a desired behaviour? I found the effects quite surprising
and counter-intuitive, until I understood what was going on.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12401