Skip to content

Commit

Permalink
Added C++11 version of the against-value-to-function-cast error. Fixe…
Browse files Browse the repository at this point in the history
…d some problems reported by gcc 8
  • Loading branch information
Mikołaj Małecki authored and rndi committed Oct 29, 2019
1 parent aaff9d3 commit ad149df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
22 changes: 11 additions & 11 deletions srtcore/api.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions srtcore/utilities.h
Expand Up @@ -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

Expand All @@ -91,6 +92,11 @@ written by
#include <memory>
#include <sstream>
#include <iomanip>

#if HAVE_CXX11
#include <type_traits>
#endif

#include <cstdlib>
#include <cerrno>
#include <cstring>
Expand Down Expand Up @@ -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<Signature>::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;
}
Expand Down

0 comments on commit ad149df

Please sign in to comment.