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]

c++/8166: A static const int class variable becomes an undefined symbol.


>Number:         8166
>Category:       c++
>Synopsis:       A static const int class variable becomes an undefined symbol.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 07 19:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     mgoodman@csua.berkeley.edu
>Release:        3.3 20021007 (experimental)
>Organization:
>Environment:
System: Linux vodka 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/home2/markg/local --enable-languages=c,c++
>Description:
A static const int class variable becomes an undefined symbol in the object file.  Since the constructor refers to it, the object file does not link.

The bug is also filed at https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=75308.  In that bug, I found the behavior in Red Hat 8's gcc 3.2.  This bug is filed against CVS.

[markg@vodka markg]$ g++ testclass.cc -o testclass
/tmp/ccaUlTGx.o: In function `TestClass::TestClass[in-charge](TestClass const*)':
/tmp/ccaUlTGx.o(.gnu.linkonce.t._ZN9TestClassC1EPKS_+0x1e): undefined reference to `TestClass::notDefined'
collect2: ld returned 1 exit status

>How-To-Repeat:
g++ testclass.cc -o testclass

The preprocessed source is below.

# 1 "testclass.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "testclass.cc"
# 1 "/home2/markg/local/include/c++/3.3/cstddef" 1 3
# 47 "/home2/markg/local/include/c++/3.3/cstddef" 3

# 1 "/home2/markg/local/lib/gcc-lib/i686-pc-linux-gnu/3.3/include/stddef.h" 1 3 4
# 151 "/home2/markg/local/lib/gcc-lib/i686-pc-linux-gnu/3.3/include/stddef.h" 3 4
typedef int ptrdiff_t;
# 213 "/home2/markg/local/lib/gcc-lib/i686-pc-linux-gnu/3.3/include/stddef.h" 3 4
typedef unsigned int size_t;
# 49 "/home2/markg/local/include/c++/3.3/cstddef" 2 3

namespace std
{
  using ::ptrdiff_t;
  using ::size_t;
}
# 2 "testclass.cc" 2

class TestClass {
public:
  static const int notDefined = -1;

  TestClass(const TestClass *parent) {
    i = parent ? parent->i : notDefined;
  }

private:
  int i;
};

TestClass test(__null);

int main(void) {
  return 0;
}
	
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


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