]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50594 (Option -fwhole-program discards replaced new operator for std::string)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 12 Oct 2011 18:40:58 +0000 (18:40 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 12 Oct 2011 18:40:58 +0000 (18:40 +0000)
2011-10-12  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/50594
* decl.c (cxx_init_decl_processing): Add
__attribute__((externally_visible)) to operator new and
operator delete library fn.

2011-10-12  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/50594
* libsupc++/new (operator new, operator delete): Decorate with
__attribute__((__externally_visible__)).
* include/bits/c++config: Add _GLIBCXX_THROW.
* libsupc++/del_op.cc: Adjust.
* libsupc++/del_opv.cc: Likewise.
* libsupc++/del_opnt.cc: Likewise.
* libsupc++/del_opvnt.cc: Likewise.
* libsupc++/new_op.cc: Likewise.
* libsupc++/new_opv.cc: Likewise.
* libsupc++/new_opnt.cc: Likewise.
* libsupc++/new_opvnt.cc: Likewise.
* testsuite/18_support/50594.cc: New.
* testsuite/ext/profile/mutex_extensions_neg.cc: Adjust dg-error
line number.

From-SVN: r179863

15 files changed:
gcc/cp/ChangeLog
gcc/cp/decl.c
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/c++config
libstdc++-v3/libsupc++/del_op.cc
libstdc++-v3/libsupc++/del_opnt.cc
libstdc++-v3/libsupc++/del_opv.cc
libstdc++-v3/libsupc++/del_opvnt.cc
libstdc++-v3/libsupc++/new
libstdc++-v3/libsupc++/new_op.cc
libstdc++-v3/libsupc++/new_opnt.cc
libstdc++-v3/libsupc++/new_opv.cc
libstdc++-v3/libsupc++/new_opvnt.cc
libstdc++-v3/testsuite/18_support/50594.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc

index ca8566f0f5cd02c63ebdc063502c69692dc0bdc2..e7c5b49ff7e691d346104c7f92e1d27c11501dcf 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50594
+       * decl.c (cxx_init_decl_processing): Add
+       __attribute__((externally_visible)) to operator new and
+       operator delete library fn.
+
 2011-10-11  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        * decl.c (duplicate_decls): Delete old interface with two parallel
index c8f325548cb75b5d147e0191d71e41c700d38c9d..8b5033f32060b2884d5bb67d7872f0b95028ed8c 100644 (file)
@@ -3654,7 +3654,7 @@ cxx_init_decl_processing (void)
   current_lang_name = lang_name_cplusplus;
 
   {
-    tree newattrs;
+    tree newattrs, extvisattr;
     tree newtype, deltype;
     tree ptr_ftype_sizetype;
     tree new_eh_spec;
@@ -3684,12 +3684,15 @@ cxx_init_decl_processing (void)
 
     /* Ensure attribs.c is initialized.  */
     init_attributes ();
-    newattrs
-      = build_tree_list (get_identifier ("alloc_size"),
-                        build_tree_list (NULL_TREE, integer_one_node));
+    extvisattr = build_tree_list (get_identifier ("externally_visible"),
+                                 NULL_TREE);
+    newattrs = tree_cons (get_identifier ("alloc_size"),
+                         build_tree_list (NULL_TREE, integer_one_node),
+                         extvisattr);
     newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
     newtype = build_exception_variant (newtype, new_eh_spec);
-    deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
+    deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
+    deltype = build_exception_variant (deltype, empty_except_spec);
     push_cp_library_fn (NEW_EXPR, newtype);
     push_cp_library_fn (VEC_NEW_EXPR, newtype);
     global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);
index 628e213f1fc8d82da4d9c77f47eddbd76f997a50..31bf711d7e5bf7b3d34d0a7eb158b091740c2970 100644 (file)
@@ -1,3 +1,21 @@
+2011-10-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50594
+       * libsupc++/new (operator new, operator delete): Decorate with
+       __attribute__((__externally_visible__)).
+       * include/bits/c++config: Add _GLIBCXX_THROW.
+       * libsupc++/del_op.cc: Adjust.
+       * libsupc++/del_opv.cc: Likewise.
+       * libsupc++/del_opnt.cc: Likewise.
+       * libsupc++/del_opvnt.cc: Likewise.
+       * libsupc++/new_op.cc: Likewise.
+       * libsupc++/new_opv.cc: Likewise.
+       * libsupc++/new_opnt.cc: Likewise.
+       * libsupc++/new_opvnt.cc: Likewise.
+       * testsuite/18_support/50594.cc: New.
+       * testsuite/ext/profile/mutex_extensions_neg.cc: Adjust dg-error
+       line number.
+
 2011-10-11  Emil Wojak  <emil@wojak.eu>
 
        PR c++/50661
index 8c61de311d43e5337644273ccda4e7f674b6ca66..f77da5ee1a70211b820d08828824fdac51c16fe5 100644 (file)
 # ifdef __GXX_EXPERIMENTAL_CXX0X__
 #  define _GLIBCXX_NOEXCEPT noexcept
 #  define _GLIBCXX_USE_NOEXCEPT noexcept
+#  define _GLIBCXX_THROW(_EXC)
 # else
 #  define _GLIBCXX_NOEXCEPT
 #  define _GLIBCXX_USE_NOEXCEPT throw()
+#  define _GLIBCXX_THROW(_EXC) throw(_EXC)
 # endif
 #endif
 
index 86d4c1e298590dac7dbdfacaf861f99925960624..0d69aa3aa35aaa351d99d987db0a8b591d900608 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2007, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2007, 2009, 2010, 2011
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -41,7 +42,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
 #include "new"
 
 _GLIBCXX_WEAK_DEFINITION void
-operator delete(void* ptr) throw ()
+operator delete(void* ptr) _GLIBCXX_USE_NOEXCEPT
 {
   if (ptr)
     std::free(ptr);
index 29eab1022ee454ebad9d05d92e12cbadcead86cd..1a43ca4e7894983ed4c76ec3d0aabfabb618f75c 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -29,7 +30,7 @@
 extern "C" void free (void *);
 
 _GLIBCXX_WEAK_DEFINITION void
-operator delete (void *ptr, const std::nothrow_t&) throw ()
+operator delete (void *ptr, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
 {
   free (ptr);
 }
index c56df07d9d78267658d98823cc5f4efc768f8ffc..594f86262d79de9499c9d911bd76499ea0076aa7 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -27,7 +28,7 @@
 #include "new"
 
 _GLIBCXX_WEAK_DEFINITION void
-operator delete[] (void *ptr) throw ()
+operator delete[] (void *ptr) _GLIBCXX_USE_NOEXCEPT
 {
   ::operator delete (ptr);
 }
index fec64953e639d3ecc7842fa9f02ff80c27d4b36f..e27eb5826e37592cbbcebd0770bffdd927b69380 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -27,7 +28,7 @@
 #include "new"
 
 _GLIBCXX_WEAK_DEFINITION void
-operator delete[] (void *ptr, const std::nothrow_t&) throw ()
+operator delete[] (void *ptr, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
 {
   ::operator delete (ptr);
 }
index 80ee3ba0fd89332e3cc5f8f5254853e5e9b6ef81..1c258002e658d07967cf5e9d212d14daef2b6545 100644 (file)
@@ -1,7 +1,7 @@
 // The -*- C++ -*- dynamic memory management header.
 
 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-// 2003, 2004, 2005, 2006, 2007, 2009, 2010
+// 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
 // Free Software Foundation
 
 // This file is part of GCC.
@@ -90,22 +90,32 @@ namespace std
  *  Placement new and delete signatures (take a memory address argument,
  *  does nothing) may not be replaced by a user's program.
 */
-void* operator new(std::size_t) throw (std::bad_alloc);
-void* operator new[](std::size_t) throw (std::bad_alloc);
-void operator delete(void*) throw();
-void operator delete[](void*) throw();
-void* operator new(std::size_t, const std::nothrow_t&) throw();
-void* operator new[](std::size_t, const std::nothrow_t&) throw();
-void operator delete(void*, const std::nothrow_t&) throw();
-void operator delete[](void*, const std::nothrow_t&) throw();
+void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
+  __attribute__((__externally_visible__));
+void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
+  __attribute__((__externally_visible__));
+void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
+void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
+void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
+void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
+void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
+void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
+  __attribute__((__externally_visible__));
 
 // Default placement versions of operator new.
-inline void* operator new(std::size_t, void* __p) throw() { return __p; }
-inline void* operator new[](std::size_t, void* __p) throw() { return __p; }
+inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
+{ return __p; }
+inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
+{ return __p; }
 
 // Default placement versions of operator delete.
-inline void  operator delete  (void*, void*) throw() { }
-inline void  operator delete[](void*, void*) throw() { }
+inline void operator delete  (void*, void*) _GLIBCXX_USE_NOEXCEPT { }
+inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { }
 //@}
 } // extern "C++"
 
index c61e941bcff8b9a37c65c52a526b1dd5f2d394e2..bb0199e969e3c50ae7aea9d79fcb72dfcb6d5827 100644 (file)
@@ -42,7 +42,7 @@ extern "C" void *malloc (std::size_t);
 extern new_handler __new_handler;
 
 _GLIBCXX_WEAK_DEFINITION void *
-operator new (std::size_t sz) throw (std::bad_alloc)
+operator new (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc)
 {
   void *p;
 
index 1bcdead5846e84b264c6da49964f34f322e86d8e..71600a63c3d1fd2c02b45496e7830cc3698c425c 100644 (file)
@@ -34,7 +34,7 @@ extern "C" void *malloc (std::size_t);
 extern new_handler __new_handler;
 
 _GLIBCXX_WEAK_DEFINITION void *
-operator new (std::size_t sz, const std::nothrow_t&) throw()
+operator new (std::size_t sz, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
 {
   void *p;
 
index b200e23c3ec4f783f572f464594123c59df2e88d..4080bd25b4f1bf0e14c6862a9ffc855c9a3719d3 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -27,7 +28,7 @@
 #include "new"
 
 _GLIBCXX_WEAK_DEFINITION void*
-operator new[] (std::size_t sz) throw (std::bad_alloc)
+operator new[] (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc)
 {
   return ::operator new(sz);
 }
index da4ae80b6971d83b460a8794a4d12ff7f95fefa5..0609e687ab7fe1870d8f0fa907884948d7ab5d53 100644 (file)
@@ -1,6 +1,7 @@
 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation
+// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011
+// Free Software Foundation
 //
 // This file is part of GCC.
 //
@@ -27,7 +28,8 @@
 #include "new"
  
 _GLIBCXX_WEAK_DEFINITION void*
-operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
+operator new[] (std::size_t sz, const std::nothrow_t& nothrow)
+  _GLIBCXX_USE_NOEXCEPT
 {
   return ::operator new(sz, nothrow);
 }
diff --git a/libstdc++-v3/testsuite/18_support/50594.cc b/libstdc++-v3/testsuite/18_support/50594.cc
new file mode 100644 (file)
index 0000000..047f4a7
--- /dev/null
@@ -0,0 +1,72 @@
+// { dg-options "-fwhole-program" }
+
+// Copyright (C) 2011 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <new>
+#include <string>
+#include <cstdlib>
+#include <testsuite_hooks.h>
+
+bool user_new_called;
+bool user_delete_called;
+
+void* operator new(std::size_t n)
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+  throw(std::bad_alloc)
+#endif
+{
+  user_new_called = true;
+
+  void* p = std::malloc(n);
+
+  if (!p)
+    throw std::bad_alloc();
+
+  return p;
+}
+
+void operator delete(void* p)
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  noexcept
+#else
+  throw()
+#endif
+{
+  user_delete_called = true;
+
+  std::free(p);
+}
+
+// libstdc++/50594
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  {
+    std::string s = "Hello World.";
+  }
+
+  VERIFY( user_new_called );
+  VERIFY( user_delete_called );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
index ba515b7fb6b4141af39ec4f5a067282bd8ab16d6..4e2d071b8336d1b4cd4a6804c26ad3df1d1c70c7 100644 (file)
@@ -25,4 +25,4 @@
 
 #include <vector>
 
-// { dg-error "multiple inlined namespaces" "" { target *-*-* } 256 }
+// { dg-error "multiple inlined namespaces" "" { target *-*-* } 258 }