This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/47396] Link error when declare a constant reference to a class or struct static const member!
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 21 Jan 2011 13:50:20 +0000
- Subject: [Bug c++/47396] Link error when declare a constant reference to a class or struct static const member!
- Auto-submitted: auto-generated
- References: <bug-47396-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47396
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-01-21 13:49:32 UTC ---
GCC bugzilla is not a place to learn C++, just read the standard, in particular
[class.static.data]/4:
"If a static data member is of const integral or const enumeration 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 within its scope. 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."
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-01-21 13:49:32 UTC ---
(In reply to comment #2)
> but like this:
>
> struct test
> {
> static const int i = 0;
> };
>
> int main(void)
> {
> const unsigned int &m = test::i;
> }
>
>
> no link errors!!!! why???
a temporary (of type unsigned) has to be created, and the reference binds to
the temporary, not to test::i
This is invalid, please don't reopen it