This is the mail archive of the 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


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?


2006-11-07 Douglas Gregor <>

* cp-tree.def (STATIC_ASSERT_DECL): New.
cannot have a full lang_decl.
(finish_static_assert): Declare.
(cp_init_ts): STATIC_ASSERT_DECL has decl_common and decl_minimal
* pt.c (instantiate_class_template): Handle STATIC_ASSERT_DECL
(tsubst_expr): Handle STATIC_ASSERT_DECL statements.
* semantics.c (add_decl_expr): Static assertions have no cleanup
(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 <>

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

2006-11-07 Douglas Gregor <>

* 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]