diff options
author | Douglas Gregor <doug.gregor@gmail.com> | 2006-11-21 20:23:03 +0000 |
---|---|---|
committer | Doug Gregor <dgregor@gcc.gnu.org> | 2006-11-21 20:23:03 +0000 |
commit | 55a3debe44095349b898ca6e297b0ecb9f9d16b6 (patch) | |
tree | b93947409f894b645ef269b5199ac8efb6894453 /gcc/cp/semantics.c | |
parent | 218f00156cf583db14b1398ca52da12f59383fb3 (diff) | |
download | gcc-55a3debe44095349b898ca6e297b0ecb9f9d16b6.zip gcc-55a3debe44095349b898ca6e297b0ecb9f9d16b6.tar.gz gcc-55a3debe44095349b898ca6e297b0ecb9f9d16b6.tar.bz2 |
cp-tree.def (STATIC_ASSERT): New.
2006-11-21 Douglas Gregor <doug.gregor@gmail.com>
* cp-tree.def (STATIC_ASSERT): New.
* cp-objcp-common.c (cp_tree_size): Handle STATIC_ASSERT.
* error.c (dump_decl): Handle STATIC_ASSERT.
* cp-tree.h (STATIC_ASSERT_CONDITION): New.
(STATIC_ASSERT_MESSAGE): New.
(STATIC_ASSERT_SOURCE_LOCATION): New.
(struct tree_static_assert): New.
(enum cp_tree_node_structure_enum): Add TS_CP_STATIC_ASSERT.
(union lang_tree_node): Add static_assertion.
(finish_static_assert): Declare.
* cxx-pretty-print.c (pp_cxx_statement): Handle STATIC_ASSERT.
(pp_cxx_declaration): Handle STATIC_ASSERT.
* pt.c (instantiate_class_template): Handle
STATIC_ASSERT members.
(tsubst_expr): Handle STATIC_ASSERT statements.
* semantics.c (finish_static_assert): New.
* lex.c (D_CPP0X): New.
(reswords): Add static_assert keyword.
(init_reswords): If not flag_cpp0x, mask out C++0x keywords.
* parser.c (cp_parser_block_declaration): Parse static
assertions.
(cp_parser_static_assert): New.
(cp_parser_member_declaration): Parse static assertions.
From-SVN: r119066
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" |