This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] C++0x static assertions


Hello,

Picking off some low-hanging fruit for the C++0x mode...

The attached patch introduces static assertions into the C++ front end, as specified in the latest C++0x working draft (N2009). The feature is under the control of -std=(c|gnu)++0x. However, the uglified "__static_assert" form can always be used, resulting in a warning.

The attached patch has C++ front end bits, a change to c-common.h that adds RID_STATIC_ASSERT, and some tests in a new testsuite directory, g++.dg/cpp0x. ChangeLogs follow.

Tested powerpc-apple-darwin8.8.0; no new regressions. Also tested with a tweaked Boost that maps BOOST_STATIC_ASSERT -> static_assert; no regressions, and much nicer error messages :)

Okay for mainline?

	Cheers,
	Doug

2006-11-07 Douglas Gregor <doug.gregor@gmail.com>

* cp-tree.def (STATIC_ASSERT_DECL): New.
* cp-tree.h (CAN_HAVE_FULL_LANG_DECL_P): STATIC_ASSERT_DECLs
cannot have a full lang_decl.
(STATIC_ASSERT_COND): New.
(STATIC_ASSERT_MSG): New.
(finish_static_assert): Declare.
(cp_init_ts): STATIC_ASSERT_DECL has decl_common and decl_minimal
structures.
* pt.c (instantiate_class_template): Handle STATIC_ASSERT_DECL
members.
(tsubst_expr): Handle STATIC_ASSERT_DECL statements.
* semantics.c (add_decl_expr): Static assertions have no cleanup
points.
(finish_member_declaration): Static assertions have no linkage
information; they are entered into the scope of the class.
(finish_static_assert): New.
* lex.c (D_CPP0X): New.
(reswords): Add __static_assert, static_assert keywords.
(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.


2006-11-07 Douglas Gregor <doug.gregor@gmail.com>

        * g++.dg/cpp0x/static_assert1.C: New.
        * g++.dg/cpp0x/static_assert2.C: New.

2006-11-07 Douglas Gregor <doug.gregor@gmail.com>

* c-common.h (enum rid): Add RID_STATIC_ASSERT.

Attachment: static_assert.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]