aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-10 21:58:23 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-10 21:58:23 +0000
commitdf5390a9de5322cbaab3def921d3d517d4494144 (patch)
tree387fdc4230f85dcbe03d25081a8bef0f7568d826 /gcc/cp/semantics.c
parent9746898380044744fe0a62b01bb2a97825c644a9 (diff)
Implement C++17 constexpr if.
* cp-tree.h (IF_STMT_CONSTEXPR_P): New. * name-lookup.c (push_to_top_level, pop_from_top_level_1): Handle it. * parser.h (struct cp_parser): Add in_discarded_stmt field. * parser.c (cp_parser_selection_statement): Handle 'if constexpr'. (cp_parser_jump_statement): Avoid deducing from a discarded return. * pt.c (tsubst_expr): Only instantiate taken branch of constexpr if. * semantics.c (begin_if_stmt): Set the binding level this_entity. (finish_if_stmt_cond): Require the condition of a constexpr if to be constant. * decl.c (level_for_constexpr_if): New. (named_label_entry): Add in_constexpr_if field. (poplevel_named_label_1): Set it. (check_goto): Check it. (check_previous_goto_1): Check level_for_constexpr_if. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239338 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r--gcc/cp/semantics.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index bffdddbb965..a2e04f6b61d 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -715,6 +715,7 @@ begin_if_stmt (void)
scope = do_pushlevel (sk_cond);
r = build_stmt (input_location, IF_STMT, NULL_TREE,
NULL_TREE, NULL_TREE, scope);
+ current_binding_level->this_entity = r;
begin_cond (&IF_COND (r));
return r;
}
@@ -722,12 +723,18 @@ begin_if_stmt (void)
/* Process the COND of an if-statement, which may be given by
IF_STMT. */
-void
+tree
finish_if_stmt_cond (tree cond, tree if_stmt)
{
- finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond));
+ cond = maybe_convert_cond (cond);
+ if (IF_STMT_CONSTEXPR_P (if_stmt)
+ && require_potential_rvalue_constant_expression (cond)
+ && !value_dependent_expression_p (cond))
+ cond = cxx_constant_value (cond, NULL_TREE);
+ finish_cond (&IF_COND (if_stmt), cond);
add_stmt (if_stmt);
THEN_CLAUSE (if_stmt) = push_stmt_list ();
+ return cond;
}
/* Finish the then-clause of an if-statement, which may be given by