* decl.c (check_initializer): Check DECL_INITIALIZED_IN_CLASS_P.
* typeck2.c (store_init_value): Likewise.
Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r259571
+2018-04-23 Jakub Jelinek <jakub@redhat.com>
+ Jason Merrill <jason@redhat.com>
+
+ PR c++/85470 - wrong error with static data member.
+ * decl.c (check_initializer): Check DECL_INITIALIZED_IN_CLASS_P.
+ * typeck2.c (store_init_value): Likewise.
+
2018-04-20 Jakub Jelinek <jakub@redhat.com>
PR c++/85462
}
if (init_code
- && (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl)))
+ && (DECL_IN_AGGR_P (decl)
+ && DECL_INITIALIZED_IN_CLASS_P (decl)
+ && !DECL_VAR_DECLARED_INLINE_P (decl)))
{
static int explained = 0;
bool const_init;
value = fold_non_dependent_expr (value);
if (DECL_DECLARED_CONSTEXPR_P (decl)
- || (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl)))
+ || (DECL_IN_AGGR_P (decl)
+ && DECL_INITIALIZED_IN_CLASS_P (decl)
+ && !DECL_VAR_DECLARED_INLINE_P (decl)))
{
- /* Diagnose a non-constant initializer for constexpr. */
+ /* Diagnose a non-constant initializer for constexpr variable or
+ non-inline in-class-initialized static data member. */
if (!require_constant_expression (value))
value = error_mark_node;
else
--- /dev/null
+// PR c++/85470
+// { dg-do compile { target c++11 } }
+
+template <class T>
+struct StaticObject
+{
+ static T& create()
+ {
+ static T t;
+ return t;
+ }
+
+ static T & instance;
+};
+
+template <class T> T & StaticObject<T>::instance = StaticObject<T>::create();
+
+extern template class StaticObject<int>;
+
+void test()
+{
+ StaticObject<int>::instance;
+}