[Bug c++/20484] New: No proper linkage created for in class initialized static const

2005-03-15 Thread dopheide at fmf dot nl
Example:
template 
T const max1(T const a, T const b)
{ return a < b ? b : a; }

template 
T const & max2(T const & a, T const & b)
{ return a < b ? b : a; }

struct Test
{ static int const A = 1; };

int main()
{
#if 0
  max1(Test::A, 2); // OK.
#else
  max2(Test::A, 2); // Does not link: undefined reference to `Test::A
#endif
}

The problem does not appear in 2.95.4
The problem does appear in 3.0.4, 3.2.3
Also appeared on 3.4.4 x86_64

-- 
   Summary: No proper linkage created for in class initialized
static const
   Product: gcc
   Version: 3.3.5
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
    ReportedBy: dopheide at fmf dot nl
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-linux
  GCC host triplet: i486-linux
GCC target triplet: i486-linux


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


[Bug c++/20484] No proper linkage created for in class initialized static const

2005-03-15 Thread dopheide at fmf dot nl

--- Additional Comments From dopheide at fmf dot nl  2005-03-15 18:46 
---
You are correct. I was wrong.

I thought, because of consistency reasons, that
1) both should link, or
2) both shouldn't link.
(And I choose 1) for the "bug"-report.)

As I now understand it, the "static int const A = 1;" will be seen as an
"integral constant expression". If, OTOH, a reference has to be taken, it is
seen as a "normal int", thus requiring an actual definition. (It is in 9.4.2 of
the standard.)

See also bugs 14404, 13259, 15244, 17673.

(I search the bugs database before filing, but could not find it.)

It stills /looks/ inconsistent though.

-- 


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