From 3db4a9b428b760809fdff522272b95c378949e9b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 24 Jun 2004 16:07:23 -0400 Subject: [PATCH] re PR tree-optimization/16115 (double-destruction problem with argument passing via temporary (breaks auto_ptr)) PR c++/16115 * decl.c (grokparms): Give the PARM_DECL reference type if the parameter is passed by invisible reference. From-SVN: r83609 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 9 +++++++- gcc/testsuite/g++.dg/init/call1.C | 35 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/init/call1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 678e0cac13a..fee6c9a1223 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-06-24 Jason Merrill + + PR c++/16115 + * decl.c (grokparms): Give the PARM_DECL reference type if the + parameter is passed by invisible reference. + 2004-06-24 Andreas Schwab * cp-tree.h (enum cp_storage_class): Remove trailing comma. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e986cb7aa7c..2798440816f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8224,6 +8224,13 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms) if (type != error_mark_node) { + /* If this type is passed by invisible reference, make the PARM_DECL + reflect that so that alias analysis knows that the actual object + is external to the function. */ + if (TREE_ADDRESSABLE (type)) + decl = build_decl (PARM_DECL, DECL_NAME (decl), + build_reference_type (type)); + /* Top-level qualifiers on the parameters are ignored for function types. */ type = cp_build_qualified_type (type, 0); @@ -8258,7 +8265,7 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms) } if (!any_error && init) - init = check_default_argument (decl, init); + init = check_default_argument (type, init); else init = NULL_TREE; } diff --git a/gcc/testsuite/g++.dg/init/call1.C b/gcc/testsuite/g++.dg/init/call1.C new file mode 100644 index 00000000000..15b700fca8e --- /dev/null +++ b/gcc/testsuite/g++.dg/init/call1.C @@ -0,0 +1,35 @@ +// Bug c++/16115 +// { dg-do run } + +extern "C" void abort(); + +int count = 0; + +struct T { + T() { count++; } + T(const T&) { count++; } + ~T() { if (count==0) abort(); --count; } +}; + +struct auto_ptr { + T* p; + + auto_ptr(T* __p) : p(__p) { } + ~auto_ptr() { delete p; } + + T* release() { + T* t = p; + p = 0; + return t; + } +}; + +void destroy (auto_ptr a) { + delete a.release(); +} + + +int main () +{ + destroy (new T); +} -- 2.30.2