[GRASS-SVN] r68818 - in grass/trunk: include/iostream lib/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 30 12:20:45 PDT 2016


Author: wenzeslaus
Date: 2016-06-30 12:20:45 -0700 (Thu, 30 Jun 2016)
New Revision: 68818

Modified:
   grass/trunk/include/iostream/mm.h
   grass/trunk/lib/iostream/mm.cpp
Log:
use exception specifiers only for C++ versions older than C++11

Tested using GCC 5.2.1.

No exception specifiers (throw(...)) fail with -std=c++98 -fexceptions.
Omitting noexcept (or throw()) fails with -std=c++11 and -std=c++14.

Using __cplusplus to get C++ standard version which defines
how the definitions in the standard library look like
and using GRASS_MM_USE_EXCEPTION_SPECIFIER we then use the right ones.

This contains old fix for -fexceptions with GCC 4.7 (see #1533, r50130)
and new fix for GCC 6 where -std=gnu++14 is by default (see #2871
and Debian Bug 811886).

Works also with clang++ -std=c++14.


Modified: grass/trunk/include/iostream/mm.h
===================================================================
--- grass/trunk/include/iostream/mm.h	2016-06-30 19:16:51 UTC (rev 68817)
+++ grass/trunk/include/iostream/mm.h	2016-06-30 19:20:45 UTC (rev 68818)
@@ -39,6 +39,11 @@
 
 #include <sys/types.h>
 
+// GCC with C++98 and -fexceptions requires exception
+// specifiers, however with C++11 and newer, using them causes an error.
+#if __cplusplus < 201103L
+#define GRASS_MM_USE_EXCEPTION_SPECIFIER
+#endif /* __cplusplus < 201103L */
 
 #define MM_REGISTER_VERSION 2
 
@@ -128,10 +133,17 @@
   void print();
 
   friend class mm_register_init;
-  friend void * operator new(size_t) throw(std::bad_alloc);
-  friend void * operator new[](size_t) throw(std::bad_alloc);
+#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
+  friend void * operator new(size_t) throw (std::bad_alloc);
+  friend void * operator new[] (size_t) throw (std::bad_alloc);
   friend void operator delete(void *) throw();
   friend void operator delete[](void *) throw();
+#else
+  friend void * operator new(size_t);
+  friend void * operator new[] (size_t);
+  friend void operator delete(void *) noexcept;
+  friend void operator delete[](void *) noexcept;
+#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */
 };
 
 

Modified: grass/trunk/lib/iostream/mm.cpp
===================================================================
--- grass/trunk/lib/iostream/mm.cpp	2016-06-30 19:16:51 UTC (rev 68817)
+++ grass/trunk/lib/iostream/mm.cpp	2016-06-30 19:20:45 UTC (rev 68818)
@@ -276,7 +276,11 @@
 
  
 /* ************************************************************ */
-void* operator new[] (size_t sz) throw(std::bad_alloc) {
+#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
+void* operator new[] (size_t sz) throw (std::bad_alloc) {
+#else
+void* operator new[] (size_t sz) {
+#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */
   void *p;
   
   MM_DEBUG cout << "new: sz=" << sz << ", register " 
@@ -327,7 +331,11 @@
 
  
 /* ************************************************************ */
-void* operator new (size_t sz) throw(std::bad_alloc) {
+#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
+void* operator new (size_t sz) throw (std::bad_alloc) {
+#else
+void* operator new (size_t sz) {
+#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */
   void *p;
   
   MM_DEBUG cout << "new: sz=" << sz << ", register " 
@@ -379,7 +387,11 @@
 
 
 /* ---------------------------------------------------------------------- */
+#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
 void operator delete (void *ptr) throw() {
+#else
+void operator delete (void *ptr) noexcept {
+#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */
   size_t sz;
   void *p;
   
@@ -419,7 +431,11 @@
 
 
 /* ---------------------------------------------------------------------- */
+#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
 void operator delete[] (void *ptr) throw() {
+#else
+void operator delete[] (void *ptr) noexcept {
+#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */
   size_t sz;
   void *p;
   



More information about the grass-commit mailing list