#define LOOKUP_DELEGATING_CONS (LOOKUP_NO_NON_INTEGRAL << 1)
/* Allow initialization of a flexible array members. */
#define LOOKUP_ALLOW_FLEXARRAY_INIT (LOOKUP_DELEGATING_CONS << 1)
-/* Require constant initialization of a non-constant variable. */
-#define LOOKUP_CONSTINIT (LOOKUP_ALLOW_FLEXARRAY_INIT << 1)
/* We're looking for either a rewritten comparison operator candidate or the
operator to use on the former's result. We distinguish between the two by
knowing that comparisons other than == and <=> must be the latter, as must
a <=> expression trying to rewrite to <=> without reversing. */
-#define LOOKUP_REWRITTEN (LOOKUP_CONSTINIT << 1)
+#define LOOKUP_REWRITTEN (LOOKUP_ALLOW_FLEXARRAY_INIT << 1)
/* Reverse the order of the two arguments for comparison rewriting. First we
swap the arguments in add_operator_candidates, then we swap the conversions
in add_candidate (so that they correspond to the original order of the
|= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
DECL_DECLARED_CONSTEXPR_P (newdecl)
|= DECL_DECLARED_CONSTEXPR_P (olddecl);
+ DECL_DECLARED_CONSTINIT_P (newdecl)
+ |= DECL_DECLARED_CONSTINIT_P (olddecl);
/* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
if (DECL_LANG_SPECIFIC (olddecl)
flags |= LOOKUP_ALREADY_DIGESTED;
}
else if (DECL_DECLARED_CONSTEXPR_P (decl)
- || (flags & LOOKUP_CONSTINIT))
+ || DECL_DECLARED_CONSTINIT_P (decl))
{
/* Declared constexpr or constinit, but no suitable initializer;
massage init appropriately so we can pass it into
DECL_INITIAL (decl) = NULL_TREE;
}
- /* Handle `constinit' on variable templates. */
- if (flags & LOOKUP_CONSTINIT)
- DECL_DECLARED_CONSTINIT_P (decl) = true;
-
/* Generally, initializers in templates are expanded when the
template is instantiated. But, if DECL is a variable constant
then it can be used in future constant expressions, so its value
/* [dcl.constinit]/1 "The constinit specifier shall be applied
only to a declaration of a variable with static or thread storage
duration." */
- if ((flags & LOOKUP_CONSTINIT)
+ if (DECL_DECLARED_CONSTINIT_P (decl)
&& !(dk == dk_thread || dk == dk_static))
{
error_at (DECL_SOURCE_LOCATION (decl),
else if (storage_class == sc_static)
DECL_THIS_STATIC (decl) = 1;
- /* Set constexpr flag on vars (functions got it in grokfndecl). */
- if (constexpr_p && VAR_P (decl))
- DECL_DECLARED_CONSTEXPR_P (decl) = true;
+ if (VAR_P (decl))
+ {
+ /* Set constexpr flag on vars (functions got it in grokfndecl). */
+ if (constexpr_p)
+ DECL_DECLARED_CONSTEXPR_P (decl) = true;
+ /* And the constinit flag (which only applies to variables). */
+ else if (constinit_p)
+ DECL_DECLARED_CONSTINIT_P (decl) = true;
+ }
/* Record constancy and volatility on the DECL itself . There's
no need to do this when processing a template; we'll do this
else
flags = LOOKUP_IMPLICIT;
- if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
- flags |= LOOKUP_CONSTINIT;
-
switch (TREE_CODE (value))
{
case VAR_DECL:
if (decl != error_mark_node)
{
- int flags = (decl_spec_seq_has_spec_p (decl_specifiers, ds_constinit)
- ? LOOKUP_CONSTINIT : 0);
cp_maybe_mangle_decomp (decl, prev, v.length ());
cp_finish_decl (decl, initializer, non_constant_p, NULL_TREE,
- (is_direct_init ? LOOKUP_NORMAL : LOOKUP_IMPLICIT)
- | flags);
+ (is_direct_init ? LOOKUP_NORMAL : LOOKUP_IMPLICIT));
cp_finish_decomp (decl, prev, v.length ());
}
}
declarations. */
if (!member_p && decl && decl != error_mark_node && !range_for_decl_p)
{
- int cf = (decl_spec_seq_has_spec_p (decl_specifiers, ds_constinit)
- ? LOOKUP_CONSTINIT : 0);
cp_finish_decl (decl,
initializer, !is_non_constant_init,
asm_specification,
`explicit' constructor is OK. Otherwise, an
`explicit' constructor cannot be used. */
((is_direct_init || !is_initialized)
- ? LOOKUP_NORMAL : LOOKUP_IMPLICIT) | cf);
+ ? LOOKUP_NORMAL : LOOKUP_IMPLICIT));
}
else if ((cxx_dialect != cxx98) && friend_p
&& decl && TREE_CODE (decl) == FUNCTION_DECL)
now. */
predeclare_vla (decl);
- bool constinit_p
- = VAR_P (decl) && DECL_DECLARED_CONSTINIT_P (decl);
- cp_finish_decl (decl, init, const_init, NULL_TREE,
- constinit_p ? LOOKUP_CONSTINIT : 0);
+ cp_finish_decl (decl, init, const_init, NULL_TREE, 0);
if (ndecl != error_mark_node)
cp_finish_decomp (ndecl, first, cnt);
push_nested_class (DECL_CONTEXT (d));
const_init = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (code_pattern);
- int flags = (DECL_DECLARED_CONSTINIT_P (d) ? LOOKUP_CONSTINIT : 0);
- cp_finish_decl (d, init, const_init, NULL_TREE, flags);
+ cp_finish_decl (d, init, const_init, NULL_TREE, 0);
if (enter_context)
pop_nested_class ();
/* [dcl.constinit]/2 "If a variable declared with the constinit
specifier has dynamic initialization, the program is
ill-formed." */
- if (flags & LOOKUP_CONSTINIT)
+ if (DECL_DECLARED_CONSTINIT_P (decl))
{
error_at (location_of (decl),
"%<constinit%> variable %qD does not have a constant "