@@ -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
{
new file mode 100644
@@ -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 "" }
@@ -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
@@ -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
{