This is the mail archive of the 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]

Bug with static variables of inline functions

The following two C++ source files, when compiled and linked together,
demonstrate an error in the way egcs handles the linkage of static
variables in inline functions.

The bug is present in the egcs 1.1 branch (I tested egcs-2.91.53), and
in the main trunk (tested egcs-2.92.00) on OpenBSD.  Note that gcc
2.8.1 does not exhibit this problem, so the bug isn't just
attributable to the inadequacies of the Unix or BSD linker.

When these files are compiled with egcs, the output is:

starting (0x2118)
starting (0x2110)

This should not be the case.  It means that foo::count does not have
the same static variable c in all compilation units.  When compiled
with g++ 2.8.1, the program outputs

starting (0x92a0)

as expected.


##### static-bug-1.C:

#include <stdio.h>

class foo {
  static int &count () { static int c; return c; }
  static void start ();
  foo () { if (!count ()++) printf ("starting (%p)\n", &count ()); }

static class foo x;

##### static-bug-2.C:

#include "static-bug-1.C"

main ()
  return 0;

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