cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
tree asmspec_tree, int flags)
{
- tree type;
vec<tree, va_gc> *cleanups = NULL;
const char *asmspec = NULL;
int was_readonly = 0;
/* Parameters are handled by store_parm_decls, not cp_finish_decl. */
gcc_assert (TREE_CODE (decl) != PARM_DECL);
- type = TREE_TYPE (decl);
+ tree type = TREE_TYPE (decl);
if (type == error_mark_node)
return;
if (decl_maybe_constant_var_p (decl)
/* FIXME setting TREE_CONSTANT on refs breaks the back end. */
&& !TYPE_REF_P (type))
- TREE_CONSTANT (decl) = 1;
+ TREE_CONSTANT (decl) = true;
}
/* This is handled mostly by gimplify.cc, but we have to deal with
not warning about int x = x; as it is a GCC extension to turn off
&& !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
suppress_warning (decl, OPT_Winit_self);
}
+ else if (VAR_P (decl)
+ && COMPLETE_TYPE_P (type)
+ && !TYPE_REF_P (type)
+ && !dependent_type_p (type)
+ && is_really_empty_class (type, /*ignore_vptr*/false))
+ /* We have no initializer but there's nothing to initialize anyway.
+ Treat DECL as constant due to c++/109876. */
+ TREE_CONSTANT (decl) = true;
if (flag_openmp
&& TREE_CODE (decl) == FUNCTION_DECL
else if (TYPE_REF_P (TREE_TYPE (expression)))
/* FIXME cp_finish_decl doesn't fold reference initializers. */
return true;
+ /* We have a constexpr variable and we're processing a template. When
+ there's lifetime extension involved (for which finish_compound_literal
+ used to create a temporary), we'll not be able to evaluate the
+ variable until instantiating, so pretend it's value-dependent. */
+ else if (DECL_DECLARED_CONSTEXPR_P (expression)
+ && !TREE_CONSTANT (expression))
+ return true;
return false;
case DYNAMIC_CAST_EXPR:
--- /dev/null
+// PR c++/109876
+// { dg-do compile { target c++11 } }
+
+using size_t = decltype(sizeof 0);
+
+namespace std {
+template <class> struct initializer_list {
+ const int *_M_array;
+ size_t _M_len;
+ constexpr size_t size() const { return _M_len; }
+};
+} // namespace std
+
+constexpr std::initializer_list<int> gnum{2};
+
+template <int> struct Array {};
+template <int> void g()
+{
+ static constexpr std::initializer_list<int> num{2};
+ static_assert(num.size(), "");
+ Array<num.size()> ctx;
+
+ constexpr Array<1> num1{};
+}
+
+template <int N>
+struct Foo
+{
+ static constexpr std::initializer_list<int> num = { 1, 2 };
+ static_assert(num.size(), "");
+ Array<num.size()> ctx;
+};
+
+void
+f (Foo<5>)
+{
+ g<0>();
+}