From 6ce8bd0cf37a9cc3a42fb258b537c15ff6189a5a Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 1 Oct 2009 14:37:08 +0000 Subject: [PATCH 1/1] * pt.c (register_specialization): Push DECL_SOURCE_LOCATION to the clones. * decl.c (grok_special_member_properties): Only adjust TYPE_HAS_COMPLEX_* if the function is defaulted in the class body. (cp_finish_decl): Push DECL_DELETED_FN/DECL_DEFAULTED_FN to the clones. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@152373 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/decl.c | 24 ++++++++++++++++++++---- gcc/cp/pt.c | 8 ++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/defaulted13.C | 29 +++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/defaulted13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a25f62b9a91..1405a5b073d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2009-10-01 Jason Merrill + + * pt.c (register_specialization): Push DECL_SOURCE_LOCATION to the + clones. + + * decl.c (grok_special_member_properties): Only adjust + TYPE_HAS_COMPLEX_* if the function is defaulted in the class body. + (cp_finish_decl): Push DECL_DELETED_FN/DECL_DEFAULTED_FN to the + clones. + 2009-09-30 Gabriel Dos Reis * decl.c (check_for_uninitialized_const_var): Check constexpr diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index cb2827dfba4..9f5ca30121d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5586,12 +5586,19 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (init && TREE_CODE (decl) == FUNCTION_DECL) { + tree clone; if (init == ridpointers[(int)RID_DELETE]) { /* FIXME check this is 1st decl. */ DECL_DELETED_FN (decl) = 1; DECL_DECLARED_INLINE_P (decl) = 1; DECL_INITIAL (decl) = error_mark_node; + FOR_EACH_CLONE (clone, decl) + { + DECL_DELETED_FN (clone) = 1; + DECL_DECLARED_INLINE_P (clone) = 1; + DECL_INITIAL (clone) = error_mark_node; + } init = NULL_TREE; } else if (init == ridpointers[(int)RID_DEFAULT]) @@ -5602,7 +5609,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, DECL_INITIAL (decl) = NULL_TREE; } else - DECL_DEFAULTED_FN (decl) = 1; + { + DECL_DEFAULTED_FN (decl) = 1; + FOR_EACH_CLONE (clone, decl) + DECL_DEFAULTED_FN (clone) = 1; + } } } @@ -9966,6 +9977,10 @@ move_fn_p (const_tree d) /* Remember any special properties of member function DECL. */ +#define DECL_DEFAULTED_IN_CLASS_P(DECL) \ + (DECL_DEFAULTED_FN (DECL) \ + && (DECL_ARTIFICIAL (DECL) || DECL_INITIALIZED_IN_CLASS_P (DECL))) + void grok_special_member_properties (tree decl) { @@ -9992,7 +10007,7 @@ grok_special_member_properties (tree decl) are no other parameters or else all other parameters have default arguments. */ TYPE_HAS_INIT_REF (class_type) = 1; - if (!DECL_DEFAULTED_FN (decl)) + if (!DECL_DEFAULTED_IN_CLASS_P (decl)) TYPE_HAS_COMPLEX_INIT_REF (class_type) = 1; if (ctor > 1) TYPE_HAS_CONST_INIT_REF (class_type) = 1; @@ -10000,7 +10015,8 @@ grok_special_member_properties (tree decl) else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl))) { TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1; - if (TREE_CODE (decl) == TEMPLATE_DECL || !DECL_DEFAULTED_FN (decl)) + if (TREE_CODE (decl) == TEMPLATE_DECL + || !DECL_DEFAULTED_IN_CLASS_P (decl)) TYPE_HAS_COMPLEX_DFLT (class_type) = 1; } else if (is_list_ctor (decl)) @@ -10019,7 +10035,7 @@ grok_special_member_properties (tree decl) if (assop) { TYPE_HAS_ASSIGN_REF (class_type) = 1; - if (!DECL_DEFAULTED_FN (decl)) + if (!DECL_DEFAULTED_IN_CLASS_P (decl)) TYPE_HAS_COMPLEX_ASSIGN_REF (class_type) = 1; if (assop != 1) TYPE_HAS_CONST_ASSIGN_REF (class_type) = 1; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5f9b07cde73..6b98956d6e6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1348,8 +1348,12 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, to the primary function; now copy the inline bits to the various clones. */ FOR_EACH_CLONE (clone, fn) - DECL_DECLARED_INLINE_P (clone) - = DECL_DECLARED_INLINE_P (fn); + { + DECL_DECLARED_INLINE_P (clone) + = DECL_DECLARED_INLINE_P (fn); + DECL_SOURCE_LOCATION (clone) + = DECL_SOURCE_LOCATION (fn); + } check_specialization_namespace (fn); return fn; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 01805ae8d3f..b3551d1bfe8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-10-01 Jason Merrill + + * g++.dg/cpp0x/defaulted13.C: New. + 2009-09-30 Dennis Wassel * gcc/testsuite/gfortran.dg/bounds_check_7.f90: Adapted error message. diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted13.C b/gcc/testsuite/g++.dg/cpp0x/defaulted13.C new file mode 100644 index 00000000000..87b8100ac77 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted13.C @@ -0,0 +1,29 @@ +// { dg-options -std=c++0x } + +template +struct NonCopyable { + NonCopyable() = default; + NonCopyable(NonCopyable const&); +}; + +template<> +NonCopyable::NonCopyable(NonCopyable const&) = delete; // { dg-error "deleted" } + +template +NonCopyable::NonCopyable(NonCopyable const&) = default; + +template<> +NonCopyable::NonCopyable(NonCopyable const&) = delete; // { dg-error "deleted" } + + +int main() +{ + NonCopyable nc_dbl; + NonCopyable nc_dbl_cpy(nc_dbl); // { dg-error "used here" } + + NonCopyable nc_int; + NonCopyable nc_int_cpy(nc_int); // { dg-error "used here" } + + NonCopyable nc_char; + NonCopyable nc_char_cpy(nc_char); +} -- 2.11.0