re PR c++/31165 (Error: symbol `an_empty_string' is already defined)
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Thu, 15 Mar 2007 01:27:29 +0000 (01:27 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Thu, 15 Mar 2007 01:27:29 +0000 (18:27 -0700)
2007-03-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR c++/31165
        * call.c  (convert_default_arg): Instead of copying the node,
        unshare it.
2007-03-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR C++/31165
        * g++.dg/other/default7.C: New test.

From-SVN: r122941

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/default7.C [new file with mode: 0644]

index 2142ac4082bc7c73cc90ff9862421d8ad084132e..7d10b2da8ed6937bf1debf6aebea5479b0ce3874 100644 (file)
@@ -1,3 +1,9 @@
+2007-03-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR c++/31165
+       * call.c  (convert_default_arg): Instead of copying the node,
+       unshare it.
+
 2007-03-15  Dirk Mueller  <dmueller@suse.de>
 
        PR c++/30860
index 53129bb881ad0b82615bf230cc99e3da2c14c76c..9d25298e7ddf6ff0a0d2fc04b44e62f3007cfacc 100644 (file)
@@ -4683,7 +4683,7 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
         VAR_DECL.  We can avoid the copy for constants, since they
         are never modified in place.  */
       if (!CONSTANT_CLASS_P (arg))
-       arg = copy_node (arg);
+       arg = unshare_expr (arg);
       arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
                                        "default argument", fn, parmnum);
       arg = convert_for_arg_passing (type, arg);
index 27974a93a513f775dcc33dc0da0544792d2da619..47d977040397c0e66ed6ec04aa1b325034cd9e6a 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-14  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR C++/31165
+       * g++.dg/other/default7.C: New test.
+
 2007-03-15  Dirk Mueller  <dmueller@suse.de>
 
        * g++.dg/warn/Wconversion2.C: New.
diff --git a/gcc/testsuite/g++.dg/other/default7.C b/gcc/testsuite/g++.dg/other/default7.C
new file mode 100644 (file)
index 0000000..ec523bf
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do assemble } */
+/* { dg-options "-O1" }*/
+// This was PR C++/31165
+// We used to copy the whole decl when we just wantted to
+// unshare some expressions for the default argument.
+class string {
+  char *ptr;
+  int len;
+  int sz;
+};
+class cset { }  _cset_init;
+string an_empty_string;
+void f(string& = an_empty_string);
+void
+h (void )
+{
+f();
+}
+
+