public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26597]  New: static const class member, ?:, undefined reference
@ 2006-03-07 19:18 teufl at weyl dot math dot tugraz dot at
  2006-03-07 19:47 ` [Bug c++/26597] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: teufl at weyl dot math dot tugraz dot at @ 2006-03-07 19:18 UTC (permalink / raw)
  To: gcc-bugs

Consider the following code:
=== bug.cpp ===
struct Test {
 static const int number=5;
 int test(const int n);
};

int Test::test(const int n)
{
 int max = number > n ? number : n;
 return max;
}

int main()
{
 Test t;
 t.test(6);
 return 0;
}
============
I get the following linker error:
/tmp/ccWCtyqx.o(.text+0x18): In function `Test::test(int)':
: undefined reference to `Test::number'
collect2: ld returned 1 exit status

I have tested g++ 3.3.5, 4.0.2, and 4.1.0. With g++ 4.* and -O2 the error
disappears. Also if one replaces the ? : by an if statement, the error
disappears. Of course, an additional "extern const int Test::number;" also
solves the problem.

Environment: i386-linux (Debian GNU/Linux)
Releases: 3.3.5, 4.0.2, 4.1.0
How-To-Repeat: g++ -o bug bug.cpp

Best regards,
Elmar


-- 
           Summary: static const class member, ?:, undefined reference
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: teufl at weyl dot math dot tugraz dot at


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


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

* [Bug c++/26597] static const class member, ?:, undefined reference
  2006-03-07 19:18 [Bug c++/26597] New: static const class member, ?:, undefined reference teufl at weyl dot math dot tugraz dot at
@ 2006-03-07 19:47 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-07 19:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-03-07 19:47 -------
Here is the relevant section of the standard (TC1, 
section 9.4.2, paragraph 4):

  If a 'static' data member is of 'const' integral or 'const' enumeral type,
  its declaration in the class definition can specify a 'constant-initializer'
  which shall be an integral constant expression (5.19).  In that case, the
  member can appear in integral constant expressions.  The member shall still
  be defined in a namespace scope if it is used in the program and the
  namespace scope definition shall not contain an 'initializer'.

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


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-03-07 19:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-07 19:18 [Bug c++/26597] New: static const class member, ?:, undefined reference teufl at weyl dot math dot tugraz dot at
2006-03-07 19:47 ` [Bug c++/26597] " pinskia at gcc dot gnu dot org

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