From 4b9f2115114eb2c3acee32ed1898201a761fd215 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 20 Jan 2017 17:53:44 +0000 Subject: [PATCH] PR c++/78495 - wrong code inherited ctor and invisi-ref parm PR c++/78495 - wrong code inherited ctor and invisi-ref parm * cp-gimplify.c (cp_generize_r): Don't skip thunks. PR c++/79495 * g++.dg/cpp1z/inh-ctor38.C: New. From-SVN: r244728 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/cp-gimplify.c | 10 +------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C | 31 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b71c90f742..d1ad2eb5c72 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-01-20 Nathan Sidwell + + PR c++/78495 - wrong code inherited ctor and invisi-ref parm + * cp-gimplify.c (cp_generize_r): Don't skip thunks. + 2017-01-20 David Malcolm PR c++/77829 diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index e792cfde71b..2c59c076270 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1103,15 +1103,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) && omp_var_to_track (stmt)) omp_cxx_notice_variable (wtd->omp_ctx, stmt); - /* Don't dereference parms in a thunk, pass the references through. */ - if ((TREE_CODE (stmt) == CALL_EXPR && CALL_FROM_THUNK_P (stmt)) - || (TREE_CODE (stmt) == AGGR_INIT_EXPR && AGGR_INIT_FROM_THUNK_P (stmt))) - { - *walk_subtrees = 0; - return NULL; - } - - /* Otherwise, do dereference invisible reference parms. */ + /* Dereference invisible reference parms. */ if (wtd->handle_invisiref_parm_p && is_invisiref_parm (stmt)) { *stmt_p = convert_from_reference (stmt); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 69ba36cc7e8..dbbe3455c79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-01-20 Nathan Sidwell + + PR c++/79495 + * g++.dg/cpp1z/inh-ctor38.C: New. + 2017-01-20 Marek Polacek PR c/79152 diff --git a/gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C b/gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C new file mode 100644 index 00000000000..fbee8ca5c9e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C @@ -0,0 +1,31 @@ +// { dg-do run { target c++11 } } +// PR78495 failed to propagate pass-by-value struct to base ctor. + +struct Ptr { + void *ptr = 0; + + Ptr() {} + Ptr(Ptr const&) = delete; + Ptr(Ptr&& other) : ptr (other.ptr) {} +}; + +struct Base { + Ptr val; + Base(Ptr val_) : val(static_cast(val_)) {} +}; + +struct Derived: Base { + using Base::Base; +}; + +void *Foo () { + Ptr ptr; + + Derived d(static_cast(ptr)); + + return d.val.ptr; +} + +int main () { + return Foo () != 0; +} -- 2.30.2