diff options
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e3dc3ab..9192aff 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3914,5 +3914,57 @@ void init_cp_semantics (void) { } + +/* Build a STATIC_ASSERT for a static assertion with the condition + CONDITION and the message text MESSAGE. LOCATION is the location + of the static assertion in the source code. When MEMBER_P, this + static assertion is a member of a class. */ +void +finish_static_assert (tree condition, tree message, location_t location, + bool member_p) +{ + if (type_dependent_expression_p (condition) + || value_dependent_expression_p (condition)) + { + /* We're in a template; build a STATIC_ASSERT and put it in + the right place. */ + tree assertion; + + assertion = make_node (STATIC_ASSERT); + STATIC_ASSERT_CONDITION (assertion) = condition; + STATIC_ASSERT_MESSAGE (assertion) = message; + STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; + + if (member_p) + maybe_add_class_template_decl_list (current_class_type, + assertion, + /*friend_p=*/0); + else + add_stmt (assertion); + + return; + } + + /* Fold the expression and convert it to a boolean value. */ + condition = fold_non_dependent_expr (condition); + condition = cp_convert (boolean_type_node, condition); + + if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) + /* Do nothing; the condition is satisfied. */ + ; + else + { + location_t saved_loc = input_location; + + input_location = location; + if (TREE_CODE (condition) == INTEGER_CST + && integer_zerop (condition)) + /* Report the error. */ + error ("static assertion failed: %E", message); + else if (condition && condition != error_mark_node) + error ("non-constant condition for static assertion"); + input_location = saved_loc; + } +} #include "gt-cp-semantics.h" |