Bug 47897 - [4.6 Regression][C++0x] static const member variable is not constant expression
Summary: [4.6 Regression][C++0x] static const member variable is not constant expression
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 major
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-25 21:16 UTC by Kohei Takahashi
Modified: 2011-02-27 16:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-02-26 00:13:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kohei Takahashi 2011-02-25 21:16:53 UTC
GCC4.6.0(with C++0x mode) reject static const member variable depending template parameter type.

---- testcase.C ----
template < typename T, T N >
struct S
{
	static const T value = N;
	typedef S< T, value + 1 > next;
};
--------------------

It seems caused by r170488 (git: cfa61f8435164f3205d70c7e1c5038b2d881aa1d).

In other case, GCC accepts codes.
For example:
---- testcase.C (accepted) ----
template < int N >
struct S
{
	static const int value = N;
	typedef S< value + 1 > next;
};
-------------------------------

Another case:
---- testcase.C (accepted) ----
template < typename T, T N >
struct S
{
	static constexpr T value = N;
	typedef S< T, value + 1 > next;
};
-------------------------------
Comment 1 Paolo Carlini 2011-02-26 00:13:26 UTC
Urgh, I can confirm this. Jason, can you have a look?
Comment 2 Jason Merrill 2011-02-26 18:24:28 UTC
Oops.
Comment 3 Jason Merrill 2011-02-27 08:13:22 UTC
Author: jason
Date: Sun Feb 27 08:13:16 2011
New Revision: 170532

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170532
Log:
	PR c++/47897
	* semantics.c (non_const_var_error): Split out from...
	(cxx_eval_constant_expression): ...here.
	(potential_constant_expression_1) [VAR_DECL]: Use it.
	Allow dependent variables.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/regress/template-const1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/regress/debug-debug7.C
    trunk/gcc/testsuite/g++.dg/cpp0x/regress/template-function1.C
    trunk/gcc/testsuite/g++.dg/debug/debug7.C
    trunk/gcc/testsuite/g++.dg/template/function1.C
Comment 4 Jakub Jelinek 2011-02-27 16:01:40 UTC
Fixed.