public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20484] New: No proper linkage created for in class initialized static const
@ 2005-03-15 15:46 dopheide at fmf dot nl
2005-03-15 16:13 ` [Bug c++/20484] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: dopheide at fmf dot nl @ 2005-03-15 15:46 UTC (permalink / raw)
To: gcc-bugs
Example:
template <typename T>
T const max1(T const a, T const b)
{ return a < b ? b : a; }
template <typename T>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/20484] No proper linkage created for in class initialized static const
2005-03-15 15:46 [Bug c++/20484] New: No proper linkage created for in class initialized static const dopheide at fmf dot nl
@ 2005-03-15 16:13 ` pinskia at gcc dot gnu dot org
2005-03-15 18:47 ` dopheide at fmf dot nl
2005-03-15 18:50 ` pinskia at physics dot uc dot edu
2 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-15 16:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-15 16:12 -------
You need to declare space for the variable still like so:
int const Test::A;
This is invalid.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20484
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/20484] No proper linkage created for in class initialized static const
2005-03-15 15:46 [Bug c++/20484] New: No proper linkage created for in class initialized static const dopheide at fmf dot nl
2005-03-15 16:13 ` [Bug c++/20484] " pinskia at gcc dot gnu dot org
@ 2005-03-15 18:47 ` dopheide at fmf dot nl
2005-03-15 18:50 ` Andrew Pinski
2005-03-15 18:50 ` pinskia at physics dot uc dot edu
2 siblings, 1 reply; 5+ messages in thread
From: dopheide at fmf dot nl @ 2005-03-15 18:47 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Bug c++/20484] No proper linkage created for in class initialized static const
2005-03-15 18:47 ` dopheide at fmf dot nl
@ 2005-03-15 18:50 ` Andrew Pinski
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2005-03-15 18:50 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
On Mar 15, 2005, at 1:46 PM, dopheide at fmf dot nl wrote:
> It stills /looks/ inconsistent though.
That is because there is an optimization going on here which is allowed
by the standard.
-- Pinski
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/20484] No proper linkage created for in class initialized static const
2005-03-15 15:46 [Bug c++/20484] New: No proper linkage created for in class initialized static const dopheide at fmf dot nl
2005-03-15 16:13 ` [Bug c++/20484] " pinskia at gcc dot gnu dot org
2005-03-15 18:47 ` dopheide at fmf dot nl
@ 2005-03-15 18:50 ` pinskia at physics dot uc dot edu
2 siblings, 0 replies; 5+ messages in thread
From: pinskia at physics dot uc dot edu @ 2005-03-15 18:50 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at physics dot uc dot edu 2005-03-15 18:50 -------
Subject: Re: No proper linkage created for in class initialized static const
On Mar 15, 2005, at 1:46 PM, dopheide at fmf dot nl wrote:
> It stills /looks/ inconsistent though.
That is because there is an optimization going on here which is allowed
by the standard.
-- Pinski
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20484
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-03-15 18:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-15 15:46 [Bug c++/20484] New: No proper linkage created for in class initialized static const dopheide at fmf dot nl
2005-03-15 16:13 ` [Bug c++/20484] " pinskia at gcc dot gnu dot org
2005-03-15 18:47 ` dopheide at fmf dot nl
2005-03-15 18:50 ` Andrew Pinski
2005-03-15 18:50 ` pinskia at physics dot uc dot edu
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).