diff --git a/srtcore/api.cpp b/srtcore/api.cpp index b1837b176..42452051b 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -2005,7 +2005,7 @@ SRTSOCKET CUDT::socket(int af, int, int) s_UDTUnited.setError(new CUDTException(e)); return INVALID_SOCK; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return INVALID_SOCK; @@ -2031,7 +2031,7 @@ int CUDT::bind(SRTSOCKET u, const sockaddr* name, int namelen) s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2057,7 +2057,7 @@ int CUDT::bind(SRTSOCKET u, UDPSOCKET udpsock) s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2082,7 +2082,7 @@ int CUDT::listen(SRTSOCKET u, int backlog) s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2128,7 +2128,7 @@ int CUDT::connect( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2259,7 +2259,7 @@ int CUDT::send(SRTSOCKET u, const char* buf, int len, int) s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2308,7 +2308,7 @@ int CUDT::sendmsg( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2335,7 +2335,7 @@ int CUDT::sendmsg2( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2403,7 +2403,7 @@ int64_t CUDT::sendfile( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2461,7 +2461,7 @@ int CUDT::select( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; @@ -2497,7 +2497,7 @@ int CUDT::selectEx( s_UDTUnited.setError(new CUDTException(e)); return ERROR; } - catch (bad_alloc) + catch (bad_alloc&) { s_UDTUnited.setError(new CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0)); return ERROR; diff --git a/srtcore/utilities.h b/srtcore/utilities.h index ee8cfda69..d323a1651 100755 --- a/srtcore/utilities.h +++ b/srtcore/utilities.h @@ -68,12 +68,13 @@ written by #define ATR_OVERRIDE #define ATR_FINAL -#if defined(REQUIRE_CXX11) && REQUIRE_CXX11 == 1 -#error "The currently compiled application required C++11, but your compiler doesn't support it." #endif +#if !HAVE_CXX11 && defined(REQUIRE_CXX11) && REQUIRE_CXX11 == 1 +#error "The currently compiled application required C++11, but your compiler doesn't support it." #endif + // Windows warning disabler #define _CRT_SECURE_NO_WARNINGS 1 @@ -91,6 +92,11 @@ written by #include #include #include + +#if HAVE_CXX11 +#include +#endif + #include #include #include @@ -681,7 +687,17 @@ struct CallbackHolder { // Test if the pointer is a pointer to function. Don't let // other type of pointers here. +#if HAVE_CXX11 + static_assert(std::is_function::value, "CallbackHolder is for functions only!"); +#else + // This is a poor-man's replacement, which should in most compilers + // generate a warning, if `Signature` resolves to a value type. + // This would make an illegal pointer cast from a value to a function type. + // Casting function-to-function, however, should not. Unfortunately + // newer compilers disallow that, too (when a signature differs), but + // then they should better use the C++11 way, much more reliable and safer. void* (*testfn)(void*) ATR_UNUSED = (void*(*)(void*))f; +#endif opaque = o; fn = f; }