This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12401] G++ generates boguous weak definition of library routine


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]