re PR c++/46930 ([C++0x] ICE with static constexpr data member)

PR c++/46930
	* decl.c (grokdeclarator): Reject uninitialized constexpr
	static data member.

From-SVN: r167834
This commit is contained in:
Jason Merrill 2010-12-14 19:35:17 -05:00 committed by Jason Merrill
parent ece17375aa
commit 6da9537811
6 changed files with 34 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2010-12-14 Jason Merrill <jason@redhat.com>
PR c++/46930
* decl.c (grokdeclarator): Reject uninitialized constexpr
static data member.
2010-12-14 Nathan Froyd <froydnj@codesourcery.com>
PR c++/45330

View file

@ -9763,6 +9763,13 @@ grokdeclarator (const cp_declarator *declarator,
if (thread_p)
DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
if (constexpr_p && !initialized)
{
error ("constexpr static data member %qD must have an "
"initializer", decl);
constexpr_p = false;
}
}
else
{

View file

@ -1,3 +1,10 @@
2010-12-14 Jason Merrill <jason@redhat.com>
PR c++/46930
* g++.dg/cpp0x/constexpr-decl.C: New.
* g++.dg/cpp0x/constexpr-ex1.C: Fix.
* g++.dg/cpp0x/constexpr-static5.C: Fix.
2010-12-14 Jan Hubicka <jh@suse.cz>
PR lto/46940

View file

@ -0,0 +1,10 @@
// PR c++/46930
// { dg-options -std=c++0x }
struct S {
static constexpr int size; // { dg-error "must have an initializer" }
// { dg-error "previous declaration" "" { target *-*-* } 5 }
};
const int limit = 2 * S::size;
constexpr int S::size = 256; // { dg-error "" }

View file

@ -16,9 +16,9 @@ struct S {
constexpr int twice();
constexpr int t(); // { dg-message "used but never defined" }
private:
static constexpr int val; // constexpr variable
static constexpr int val = 7; // constexpr variable
};
constexpr int S::val = 7;
constexpr int S::twice() { return val + val; }
constexpr S s = { };
int x1 = s.twice(); // ok

View file

@ -3,10 +3,10 @@
template <class T>
struct A
{
constexpr static T t;
constexpr static T t = T(); // { dg-error "literal" }
};
template <class T>
constexpr T A<T>::t = T(); // { dg-error "not literal" }
constexpr T A<T>::t;
struct B
{