aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-09-10 19:18:34 -0400
committerMarek Polacek <polacek@redhat.com>2020-09-11 11:17:03 -0400
commit13144466f11036585389a0dc5826bf23d53d5616 (patch)
tree9dfe7bd6076c341c2ab13bdabd9993bca8446ac0 /gcc
parent29216f56d002982f10c33056f4b3d7f07e164122 (diff)
downloadgcc-13144466f11036585389a0dc5826bf23d53d5616.zip
gcc-13144466f11036585389a0dc5826bf23d53d5616.tar.gz
gcc-13144466f11036585389a0dc5826bf23d53d5616.tar.bz2
c++: Remove LOOKUP_CONSTINIT.
Since we now have DECL_DECLARED_CONSTINIT_P, we no longer need LOOKUP_CONSTINIT. gcc/cp/ChangeLog: * cp-tree.h (LOOKUP_CONSTINIT): Remove. (LOOKUP_REWRITTEN): Adjust. * decl.c (duplicate_decls): Set DECL_DECLARED_CONSTINIT_P. (check_initializer): Use DECL_DECLARED_CONSTINIT_P instead of LOOKUP_CONSTINIT. (cp_finish_decl): Don't set DECL_DECLARED_CONSTINIT_P. Use DECL_DECLARED_CONSTINIT_P instead of LOOKUP_CONSTINIT. (grokdeclarator): Set DECL_DECLARED_CONSTINIT_P. * decl2.c (grokfield): Don't handle LOOKUP_CONSTINIT. * parser.c (cp_parser_decomposition_declaration): Remove LOOKUP_CONSTINIT handling. (cp_parser_init_declarator): Likewise. * pt.c (tsubst_expr): Likewise. (instantiate_decl): Likewise. * typeck2.c (store_init_value): Use DECL_DECLARED_CONSTINIT_P instead of LOOKUP_CONSTINIT.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/cp-tree.h4
-rw-r--r--gcc/cp/decl.c22
-rw-r--r--gcc/cp/decl2.c3
-rw-r--r--gcc/cp/parser.c9
-rw-r--r--gcc/cp/pt.c8
-rw-r--r--gcc/cp/typeck2.c2
6 files changed, 19 insertions, 29 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b166475..5923574 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5598,13 +5598,11 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG };
#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
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
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 50a042e..fd48a21 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -994,9 +994,6 @@ grokfield (const cp_declarator *declarator,
else
flags = LOOKUP_IMPLICIT;
- if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
- flags |= LOOKUP_CONSTINIT;
-
switch (TREE_CODE (value))
{
case VAR_DECL:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 916ea6c..fed1689 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -14096,12 +14096,9 @@ cp_parser_decomposition_declaration (cp_parser *parser,
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 ());
}
}
@@ -21018,8 +21015,6 @@ cp_parser_init_declarator (cp_parser* parser,
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,
@@ -21028,7 +21023,7 @@ cp_parser_init_declarator (cp_parser* parser,
`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)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 30c6735..0f52a9e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18103,10 +18103,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_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);
@@ -25758,8 +25755,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
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 ();
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index b95f112..e259a42 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -920,7 +920,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
/* [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 "