aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f1b7fba..8922ef5 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2312,6 +2312,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
|= 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)
@@ -6884,7 +6886,7 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
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
@@ -7675,10 +7677,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
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
@@ -7782,7 +7780,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
/* [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),
@@ -13829,9 +13827,15 @@ grokdeclarator (const cp_declarator *declarator,
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