PR c++/16115
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Jun 2004 20:07:23 +0000 (20:07 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Jun 2004 20:07:23 +0000 (20:07 +0000)
        * decl.c (grokparms): Give the PARM_DECL reference type if the
        parameter is passed by invisible reference.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@83609 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/init/call1.C [new file with mode: 0644]

index 678e0ca..fee6c9a 100644 (file)
@@ -1,3 +1,9 @@
+2004-06-24  Jason Merrill  <jason@redhat.com>
+
+       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  <schwab@suse.de>
 
        * cp-tree.h (enum cp_storage_class): Remove trailing comma.
index e986cb7..2798440 100644 (file)
@@ -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 (file)
index 0000000..15b700f
--- /dev/null
@@ -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); 
+}