diff options
author | Jason Merrill <jason@redhat.com> | 2008-07-24 15:15:00 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2008-07-24 15:15:00 -0400 |
commit | b87d79e640b3e9ab1e126bb6d87472b2a261a640 (patch) | |
tree | 38c6149cb50c1486bcdf000c5463ee69d1c647a7 /gcc/cp/decl2.c | |
parent | c3005b0f0c8081ccb719740c3c27ee13d5697add (diff) | |
download | gcc-b87d79e640b3e9ab1e126bb6d87472b2a261a640.zip gcc-b87d79e640b3e9ab1e126bb6d87472b2a261a640.tar.gz gcc-b87d79e640b3e9ab1e126bb6d87472b2a261a640.tar.bz2 |
Implement defaulted/deleted functions as per N2346
Implement defaulted/deleted functions as per N2346
* cp-tree.h (struct lang_decl_flags): Add defaulted_p bitfield.
(DECL_DELETED_FN): New macro.
(DECL_DEFAULTED_FN): New macro.
* class.c (user_provided_p): New fn.
(defaultable_fn_p): New fn.
(type_has_user_provided_constructor): New fn.
(type_has_user_provided_default_constructor): New fn.
(check_methods): A defaulted fn is still trivial.
(check_bases_and_members): Likewise.
* decl.c (grok_special_member_properties): Likewise.
(duplicate_decls): Complain about redeclaring a function as deleted.
(start_decl): initialized==2 means deleted.
(cp_finish_decl): Handle deleted/defaulted semantics.
* decl2.c (grokfield): Likewise.
(mark_used): Check DECL_DEFAULTED_FN instead of DECL_ARTIFICIAL.
Complain about using a deleted fn.
* init.c (build_value_init_1): Use type_has_user_provided_constructor.
(perform_member_init): Check for a user-provided default constructor
even if TYPE_NEEDS_CONSTRUCTING.
(build_new_1): Likewise.
* call.c (build_over_call): Don't call mark_used twice.
* method.c (implicitly_declare_fn): Set DECL_DEFAULTED_FN.
* search.c (check_final_overrider): Check for deleted mismatch.
* parser.c (cp_parser_init_declarator): Tell start_decl about =delete.
(cp_parser_pure_specifier): Handle =default and =delete.
* error.c (maybe_warn_cpp0x): Suggest -std=gnu++0x as well.
From-SVN: r138123
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r-- | gcc/cp/decl2.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f14f94d..6e6151d 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -821,7 +821,25 @@ grokfield (const cp_declarator *declarator, { /* Initializers for functions are rejected early in the parser. If we get here, it must be a pure specifier for a method. */ - if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE) + if (init == ridpointers[(int)RID_DELETE]) + { + DECL_DELETED_FN (value) = 1; + DECL_DECLARED_INLINE_P (value) = 1; + DECL_INITIAL (value) = error_mark_node; + } + else if (init == ridpointers[(int)RID_DEFAULT]) + { + if (!defaultable_fn_p (value)) + error ("%qD cannot be defaulted", value); + else + { + DECL_DEFAULTED_FN (value) = 1; + DECL_INITIALIZED_IN_CLASS_P (value) = 1; + DECL_DECLARED_INLINE_P (value) = 1; + DECL_INLINE (value) = 1; + } + } + else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE) { gcc_assert (error_operand_p (init) || integer_zerop (init)); DECL_PURE_VIRTUAL_P (value) = 1; @@ -3739,7 +3757,7 @@ mark_used (tree decl) /* Is it a synthesized method that needs to be synthesized? */ if (TREE_CODE (decl) == FUNCTION_DECL && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) - && DECL_ARTIFICIAL (decl) + && DECL_DEFAULTED_FN (decl) && !DECL_THUNK_P (decl) && ! DECL_INITIAL (decl) /* Kludge: don't synthesize for default args. Unfortunately this @@ -3752,6 +3770,12 @@ mark_used (tree decl) /* If we've already synthesized the method we don't need to do the instantiation test below. */ } + else if (TREE_CODE (decl) == FUNCTION_DECL + && DECL_DELETED_FN (decl)) + { + error ("deleted function %q+D", decl); + error ("used here"); + } else if ((DECL_NON_THUNK_FUNCTION_P (decl) || TREE_CODE (decl) == VAR_DECL) && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl) && (!DECL_EXPLICIT_INSTANTIATION (decl) |