View Issue Details

IDProjectCategoryView StatusLast Update
0000827OpenMPT[All Projects] libopenmptpublic2016-07-12 09:38
ReportermanxAssigned Tomanx 
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionOpenMPT 1.26.02.* (old testing) 
Target VersionOpenMPT 1.?? (libopenmpt 1.0) (goals)Fixed in VersionOpenMPT 1.26.03.03 / libopenmpt 0.2-beta19 (upgrade first) 
Summary0000827: Use of throw() in public libopenmpt C++ header is deprecated
Description

<p>throw() exception specification is deprecated since C++11, but required to be used for C++98 and C++03. Newer compilers will probably start to warn about this starting with about C++17 (I'm guessing here). Our public header file should not trigger such trivial warnings. Since C++11, noexcept is the equivalent, and recommended as alternative to throw().</p>
<p>Possible solution:
Add a public header macro LIBOPENMPT_NOEXCEPT and define it appropriately. In order to not break any compilers that we are not able to test, provide the possibility for the library user to opt-out of auto-detection logic using __cplusplus, by suporting the following macros: LIBOPENMPT_FORCE_NOEXCEPT_CXX98 and LIBOPENMPT_FORCE_NOEXCEPT_CXX11 which could be defined before including libopenmpt.hpp.
</p>

Additional Information

This may be required to be solved even before libopenmpt 1.0.

TagsNo tags attached.
Has the bug occurred in previous versions?yes
Tested code revision (in case you know it)

Activities

manx

manx

2016-07-08 08:40

administrator  

noexcept-v1.patch (2,375 bytes)
Index: libopenmpt/libopenmpt.hpp
===================================================================
--- libopenmpt/libopenmpt.hpp	(revision 6595)
+++ libopenmpt/libopenmpt.hpp	(working copy)
@@ -117,9 +117,9 @@
 private:
 	char * text;
 public:
-	exception( const std::string & text ) throw();
-	virtual ~exception() throw();
-	virtual const char * what() const throw();
+	exception( const std::string & text ) LIBOPENMPT_NOEXCEPT;
+	virtual ~exception() LIBOPENMPT_NOEXCEPT;
+	virtual const char * what() const LIBOPENMPT_NOEXCEPT;
 }; // class exception
 
 //! Get the libopenmpt version number
Index: libopenmpt/libopenmpt_config.h
===================================================================
--- libopenmpt/libopenmpt_config.h	(revision 6595)
+++ libopenmpt/libopenmpt_config.h	(working copy)
@@ -178,6 +178,28 @@
 #endif
 #endif
 
+#ifdef __cplusplus
+#if defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX98)
+#define LIBOPENMPT_NOEXCEPT throw()
+#elif defined(IBOPENMPT_FORCE_NOEXCEPT_CXX03)
+#define LIBOPENMPT_NOEXCEPT throw()
+#elif defined(IBOPENMPT_FORCE_NOEXCEPT_CXX11)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif defined(IBOPENMPT_FORCE_NOEXCEPT_CXX14)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif defined(IBOPENMPT_FORCE_NOEXCEPT_CXX17)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 201402L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 201103L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 199711L)
+#define LIBOPENMPT_NOEXCEPT throw()
+#else
+#define LIBOPENMPT_NOEXCEPT throw()
+#endif
+#endif
+
 #include "libopenmpt_version.h"
 
 #endif /* LIBOPENMPT_CONFIG_H */
Index: libopenmpt/libopenmpt_cxx.cpp
===================================================================
--- libopenmpt/libopenmpt_cxx.cpp	(revision 6595)
+++ libopenmpt/libopenmpt_cxx.cpp	(working copy)
@@ -21,7 +21,7 @@
 
 namespace openmpt {
 
-exception::exception( const std::string & text ) throw()
+exception::exception( const std::string & text ) LIBOPENMPT_NOEXCEPT
 	: std::exception()
 	, text(0)
 {
@@ -31,7 +31,7 @@
 	}
 }
 
-exception::~exception() throw() {
+exception::~exception() LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		std::free( text );
 		text = 0;
@@ -38,7 +38,7 @@
 	}
 }
 
-const char * exception::what() const throw() {
+const char * exception::what() const LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		return text;
 	} else {
noexcept-v1.patch (2,375 bytes)
manx

manx

2016-07-08 21:05

administrator  

noexcept-v2.patch (2,379 bytes)
Index: libopenmpt/libopenmpt.hpp
===================================================================
--- libopenmpt/libopenmpt.hpp	(revision 6603)
+++ libopenmpt/libopenmpt.hpp	(working copy)
@@ -117,9 +117,9 @@
 private:
 	char * text;
 public:
-	exception( const std::string & text ) throw();
-	virtual ~exception() throw();
-	virtual const char * what() const throw();
+	exception( const std::string & text ) LIBOPENMPT_NOEXCEPT;
+	virtual ~exception() LIBOPENMPT_NOEXCEPT;
+	virtual const char * what() const LIBOPENMPT_NOEXCEPT;
 }; // class exception
 
 //! Get the libopenmpt version number
Index: libopenmpt/libopenmpt_config.h
===================================================================
--- libopenmpt/libopenmpt_config.h	(revision 6603)
+++ libopenmpt/libopenmpt_config.h	(working copy)
@@ -178,6 +178,28 @@
 #endif
 #endif
 
+#ifdef __cplusplus
+#if defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX98)
+#define LIBOPENMPT_NOEXCEPT throw()
+#elif defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX03)
+#define LIBOPENMPT_NOEXCEPT throw()
+#elif defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX11)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX14)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif defined(LIBOPENMPT_FORCE_NOEXCEPT_CXX17)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 201402L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 201103L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#elif (__cplusplus >= 199711L)
+#define LIBOPENMPT_NOEXCEPT throw()
+#else
+#define LIBOPENMPT_NOEXCEPT throw()
+#endif
+#endif
+
 #include "libopenmpt_version.h"
 
 #endif /* LIBOPENMPT_CONFIG_H */
Index: libopenmpt/libopenmpt_cxx.cpp
===================================================================
--- libopenmpt/libopenmpt_cxx.cpp	(revision 6603)
+++ libopenmpt/libopenmpt_cxx.cpp	(working copy)
@@ -21,7 +21,7 @@
 
 namespace openmpt {
 
-exception::exception( const std::string & text ) throw()
+exception::exception( const std::string & text ) LIBOPENMPT_NOEXCEPT
 	: std::exception()
 	, text(0)
 {
@@ -31,7 +31,7 @@
 	}
 }
 
-exception::~exception() throw() {
+exception::~exception() LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		std::free( text );
 		text = 0;
@@ -38,7 +38,7 @@
 	}
 }
 
-const char * exception::what() const throw() {
+const char * exception::what() const LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		return text;
 	} else {
noexcept-v2.patch (2,379 bytes)
manx

manx

2016-07-12 09:30

administrator  

noexcept-v3.patch (3,455 bytes)
Index: libopenmpt/dox/changelog.md
===================================================================
--- libopenmpt/dox/changelog.md	(revision 6617)
+++ libopenmpt/dox/changelog.md	(working copy)
@@ -9,6 +9,11 @@
 
  *  [**Change**] libopenmpt now uses C++14 `[[deprecated]]` attribute instead
     of compiler-specific solutions when appropriate.
+ *  [**Change**] libopenmpt C++ header now uses C++11 `noexcept` instead of
+    C++98 `throw()` exception specification when supported. `throw()` is
+    deprecated since C++11. This does not change API or ABI as they are
+    equivalent. Use `LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT` to override the
+    default.
 
  *  The public libopenmpt C++ header has auto-detection logics for the used C++
     standard now. I case your client code compiler misreports the standard
Index: libopenmpt/libopenmpt.hpp
===================================================================
--- libopenmpt/libopenmpt.hpp	(revision 6617)
+++ libopenmpt/libopenmpt.hpp	(working copy)
@@ -130,9 +130,9 @@
 private:
 	char * text;
 public:
-	exception( const std::string & text ) throw();
-	virtual ~exception() throw();
-	virtual const char * what() const throw();
+	exception( const std::string & text ) LIBOPENMPT_NOEXCEPT;
+	virtual ~exception() LIBOPENMPT_NOEXCEPT;
+	virtual const char * what() const LIBOPENMPT_NOEXCEPT;
 }; // class exception
 
 //! Get the libopenmpt version number
Index: libopenmpt/libopenmpt_config.h
===================================================================
--- libopenmpt/libopenmpt_config.h	(revision 6617)
+++ libopenmpt/libopenmpt_config.h	(working copy)
@@ -112,11 +112,18 @@
 /* handle known broken compilers here by defining LIBOPENMPT_ASSUME_CPLUSPLUS_DEPRECATED appropriately */
 #endif
 
+#ifndef LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT
+/* handle known broken compilers here by defining LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT appropriately */
+#endif
+
 #if defined(LIBOPENMPT_ASSUME_CPLUSPLUS)
 #ifndef LIBOPENMPT_ASSUME_CPLUSPLUS_DEPRECATED
 #define LIBOPENMPT_ASSUME_CPLUSPLUS_DEPRECATED LIBOPENMPT_ASSUME_CPLUSPLUS
 #endif
+#ifndef LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT
+#define LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT LIBOPENMPT_ASSUME_CPLUSPLUS
 #endif
+#endif
 
 #endif
 
@@ -212,6 +219,20 @@
 #endif
 #endif
 
+#ifdef __cplusplus
+#if defined(LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT)
+#if (LIBOPENMPT_ASSUME_CPLUSPLUS_NOEXCEPT >= 201103L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#else
+#define LIBOPENMPT_NOEXCEPT throw()
+#endif
+#elif (__cplusplus >= 201103L)
+#define LIBOPENMPT_NOEXCEPT noexcept
+#else
+#define LIBOPENMPT_NOEXCEPT throw()
+#endif
+#endif
+
 #include "libopenmpt_version.h"
 
 #endif /* LIBOPENMPT_CONFIG_H */
Index: libopenmpt/libopenmpt_cxx.cpp
===================================================================
--- libopenmpt/libopenmpt_cxx.cpp	(revision 6617)
+++ libopenmpt/libopenmpt_cxx.cpp	(working copy)
@@ -21,7 +21,7 @@
 
 namespace openmpt {
 
-exception::exception( const std::string & text ) throw()
+exception::exception( const std::string & text ) LIBOPENMPT_NOEXCEPT
 	: std::exception()
 	, text(0)
 {
@@ -31,7 +31,7 @@
 	}
 }
 
-exception::~exception() throw() {
+exception::~exception() LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		std::free( text );
 		text = 0;
@@ -38,7 +38,7 @@
 	}
 }
 
-const char * exception::what() const throw() {
+const char * exception::what() const LIBOPENMPT_NOEXCEPT {
 	if ( text ) {
 		return text;
 	} else {
noexcept-v3.patch (3,455 bytes)
manx

manx

2016-07-12 09:38

administrator   ~0002509

Fixed in r6618.

Issue History

Date Modified Username Field Change
2016-07-06 18:59 manx New Issue
2016-07-06 18:59 manx Status new => assigned
2016-07-06 18:59 manx Assigned To => manx
2016-07-08 08:40 manx File Added: noexcept-v1.patch
2016-07-08 21:05 manx File Added: noexcept-v2.patch
2016-07-12 09:30 manx File Added: noexcept-v3.patch
2016-07-12 09:38 manx Status assigned => resolved
2016-07-12 09:38 manx Resolution open => fixed
2016-07-12 09:38 manx Fixed in Version => OpenMPT 1.26.03.03 / libopenmpt 0.2-beta19 (upgrade first)
2016-07-12 09:38 manx Note Added: 0002509