Bug 49176 - [4.6 Regression][c++0x] valid code rejected with "error: uninitialized const"
[4.6 Regression][c++0x] valid code rejected with "error: uninitialized const"
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
unknown
: P3 normal
: 4.6.1
Assigned To: Jason Merrill
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-26 18:03 UTC by Roman Kononov
Modified: 2011-05-27 20:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.3, 4.7.0
Known to fail: 4.6.0
Last reconfirmed: 2011-05-27 09:00:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Kononov 2011-05-26 18:03:01 UTC
$ cat test.cpp 
struct A { static int a(); };

template<int>
struct B { static int const b; };

int f() { return B<0>::b; }

template<int I> 
int const B<I>::b=A::a();

$ g++ -c -std=c++0x test.cpp 
test.cpp: In instantiation of ‘const int B<0>::b’:
test.cpp:6:24:   instantiated from here
test.cpp:9:11: error: uninitialized const ‘B<0>::b’ [-fpermissive]
Comment 1 Jonathan Wakely 2011-05-26 19:17:23 UTC
are you using 4.6.0 or a build from the 4.6 branch?
(please always state the version in bug reports)

it seems to be fixed in 4.7

Fabien, any ideas?
Comment 2 Roman Kononov 2011-05-26 20:15:35 UTC
4.6 branch, r174294
Comment 3 fabien 2011-05-27 07:56:43 UTC
(In reply to comment #1)
> are you using 4.6.0 or a build from the 4.6 branch?
> (please always state the version in bug reports)
> 
> it seems to be fixed in 4.7
> 
> Fabien, any ideas?

I guess this is caused by my last checkin (rev 174239), which was for 4.6 only.
I'll look into it this afternoon.
Comment 4 fabien 2011-05-27 08:23:35 UTC
Is it broken in 4.6.0 before r174239 ?
Comment 5 Paolo Carlini 2011-05-27 08:58:27 UTC
Just tried -r174238: was already broken.
Comment 6 fabien 2011-05-27 16:31:42 UTC
(In reply to comment #5)
> Just tried -r174238: was already broken.

Thank you Paolo.

I've just played a little with it, it seems that to avoid the uninitialized diagnostic from check_for_uninitialized_const_var, the constness of b have to be removed at some point. It is not removed in c++0X mode for 4.6.
Let's CC Jason ...
Comment 7 Jason Merrill 2011-05-27 17:14:06 UTC
Seems like this was fixed by the patch for bug 48657.
Comment 8 Jason Merrill 2011-05-27 18:10:52 UTC
Author: jason
Date: Fri May 27 18:10:48 2011
New Revision: 174346

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174346
Log:
	PR c++/48657
	PR c++/49176
	* decl.c (cp_finish_decl): Simplify template handling.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/const5.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 9 Jason Merrill 2011-05-27 19:32:25 UTC
Author: jason
Date: Fri May 27 19:32:22 2011
New Revision: 174356

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174356
Log:
	PR c++/49176
	* g++.dg/template/const5.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/template/const5.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jason Merrill 2011-05-27 20:57:36 UTC
Fixed.