diff options
author | Jason Merrill <jason@redhat.com> | 2011-09-24 22:25:52 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-09-24 22:25:52 -0400 |
commit | 0e5f8a598de1c8dc44fb59c6d0ea0dcd557f695a (patch) | |
tree | e73c67449ead609eb0ffca593088981be94efd13 /gcc/cp/decl.c | |
parent | 77236534b98427544513ef4c159cbabdb333efd0 (diff) | |
download | gcc-0e5f8a598de1c8dc44fb59c6d0ea0dcd557f695a.zip gcc-0e5f8a598de1c8dc44fb59c6d0ea0dcd557f695a.tar.gz gcc-0e5f8a598de1c8dc44fb59c6d0ea0dcd557f695a.tar.bz2 |
Implement C++11 non-static data member initializers.
* cp-tree.h (enum cpp_warn_str): Add CPP0X_NSDMI.
* error.c (maybe_warn_cpp0x): Handle it.
* call.c (convert_like_real) [ck_user]: Don't complain about
using an explicit constructor for direct-initialization.
* class.c (check_field_decl): Fix ancient typo.
(check_field_decls): NSDMIs make the default ctor non-trivial.
* decl.c (cp_finish_decl): Record NSDMI.
(grokdeclarator): Allow NSDMI.
* decl2.c (grokfield): Allow NSDMI. Correct LOOKUP flags.
* init.c (perform_member_init): Use NSDMI.
* method.c (walk_field_subobs): Check for NSDMI.
* parser.c (cp_parser_member_declaration): Parse { } init.
* semantics.c (register_constexpr_fundef): Don't talk about
a return statement in a constexpr constructor.
(cxx_eval_call_expression): Check DECL_INITIAL instead of
DECL_SAVED_TREE.
From-SVN: r179155
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 495d8a0..661cc5e 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6075,6 +6075,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, return; } + /* Just store non-static data member initializers for later. */ + if (init && TREE_CODE (decl) == FIELD_DECL) + DECL_INITIAL (decl) = digest_init_flags (TREE_TYPE (decl), init, flags); + /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { @@ -10087,36 +10091,6 @@ grokdeclarator (const cp_declarator *declarator, if (decl == NULL_TREE) { - if (initialized) - { - if (!staticp) - { - /* An attempt is being made to initialize a non-static - member. But, from [class.mem]: - - 4 A member-declarator can contain a - constant-initializer only if it declares a static - member (_class.static_) of integral or enumeration - type, see _class.static.data_. - - This used to be relatively common practice, but - the rest of the compiler does not correctly - handle the initialization unless the member is - static so we make it static below. */ - if (cxx_dialect >= cxx0x) - { - sorry ("non-static data member initializers"); - } - else - { - permerror (input_location, "ISO C++ forbids initialization of member %qD", - unqualified_id); - permerror (input_location, "making %qD static", unqualified_id); - staticp = 1; - } - } - } - if (staticp) { /* C++ allows static class members. All other work @@ -10157,6 +10131,11 @@ grokdeclarator (const cp_declarator *declarator, DECL_MUTABLE_P (decl) = 1; storage_class = sc_none; } + + if (initialized) + /* An attempt is being made to initialize a non-static + member. This is new in C++11. */ + maybe_warn_cpp0x (CPP0X_NSDMI); } bad_specifiers (decl, BSP_FIELD, virtualp, |