* decl.c (cp_finish_decl): Don't set TREE_CONSTANT on a reference.
* typeck2.c (store_init_value): Likewise.
From-SVN: r242523
2016-11-16 Jason Merrill <jason@redhat.com>
+ PR c++/78373
+ * decl.c (cp_finish_decl): Don't set TREE_CONSTANT on a reference.
+ * typeck2.c (store_init_value): Likewise.
+
* decl.c (store_decomp_type, lookup_decomp_type): New.
(cp_finish_decomp): Call store_decomp_type.
* semantics.c (finish_decltype_type): Call lookup_decomp_type.
/* Set these flags now for templates. We'll update the flags in
store_init_value for instantiations. */
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
- if (decl_maybe_constant_var_p (decl))
+ if (decl_maybe_constant_var_p (decl)
+ /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
+ && TREE_CODE (type) != REFERENCE_TYPE)
TREE_CONSTANT (decl) = 1;
}
}
const_init = (reduced_constant_expression_p (value)
|| error_operand_p (value));
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
- TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
+ /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
+ if (TREE_CODE (type) != REFERENCE_TYPE)
+ TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
}
value = cp_fully_fold (value);
--- /dev/null
+// PR c++/78373
+// { dg-do compile { target c++11 } }
+
+struct A {
+ static A singleton;
+};
+struct B {
+ void m_fn2();
+ virtual int m_fn1();
+};
+struct D : B {
+ static int m_fn3(int, int, int, A) {
+ D &self = singleton;
+ self.m_fn2();
+ }
+ static D singleton;
+};
+template <typename, typename> struct C { bool m_fn4() const; };
+template <typename Base, typename Traits> bool C<Base, Traits>::m_fn4() const {
+ Traits::m_fn3(0, 0, 0, Base::singleton);
+}
+template struct C<A, D>;