From bc17f5fddc3e87ff0691c6e7e94c09dcd4dab771 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 6 Mar 2019 20:28:47 +0000 Subject: [PATCH] PR c++/89381 - implicit copy and using-declaration. Here the used base::operator= gets into the list of foo's bindings for operator=, but it shouldn't make the copy ctor deleted. * class.c (classtype_has_move_assign_or_move_ctor_p): Don't consider op= brought in by a using-declaration. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269442 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++ gcc/cp/class.c | 4 ++- gcc/testsuite/g++.dg/cpp0x/implicit16.C | 37 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/implicit16.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b0c1f88c6a2d..0667dd7b2f9a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-03-06 Jason Merrill + + PR c++/89381 - implicit copy and using-declaration. + * class.c (classtype_has_move_assign_or_move_ctor_p): Don't consider + op= brought in by a using-declaration. + 2019-03-06 Jakub Jelinek PR c++/87148 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0d4d35bd690a..a70a852424ed 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5220,7 +5220,9 @@ classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p) for (ovl_iterator iter (get_class_binding_direct (t, assign_op_identifier)); iter; ++iter) - if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter)) + if ((!user_p || !DECL_ARTIFICIAL (*iter)) + && DECL_CONTEXT (*iter) == t + && move_fn_p (*iter)) return true; return false; diff --git a/gcc/testsuite/g++.dg/cpp0x/implicit16.C b/gcc/testsuite/g++.dg/cpp0x/implicit16.C new file mode 100644 index 000000000000..229f2b4cd818 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/implicit16.C @@ -0,0 +1,37 @@ +// PR c++/89381 +// { dg-do compile { target c++11 } } + +template +struct base +{ + base() { } + base(const base&) { } + base(base&&) { } + base& operator=(const base&) { return *this; } + base& operator=(base&&) { return *this; } +}; + +struct foo : base +{ + using base::base; + using base::operator=; +}; + +//using workaround = decltype(foo{*static_cast(0)}); + +struct bar +{ + bar& operator=(foo ve) + { + value = ve; + return *this; + } + + foo value; +}; + +int main() +{ + foo a; + foo b{a}; +} -- 2.39.2