5_1-new: Fix building with clang/clang++ (#1866)

* Have clang and libc++ working.

If any clang users run into problems, remember to have libc++ and libc++abi set up.
Fixes
stepmania/src/arch/ArchHooks/ArchHooks.h:37:27: error:
      variable has incomplete type 'tm'
        virtual void SetTime( tm ) { }
                                 ^
/usr/include/wchar.h:83:8: note: forward declaration of 'tm'
struct tm;
       ^

* Add noexcept to swap.

See https://github.com/stepmania/stepmania/commit/e860773799f01d02f281c8c39421e7e34658788d#commitcomment-32674320

* Use standard c++11 for handling unexpected exceptions

The cxxabi.h header can make linking difficult.
This commit is contained in:
Martin Kröning
2019-08-20 18:19:52 -07:00
committed by Colby Klein
parent 4db93fc774
commit 8ab7c7fab9
5 changed files with 42 additions and 21 deletions
+2
View File
@@ -32,6 +32,8 @@ matrix:
- libxtst-dev
- libxrandr-dev
- libglew-dev
- libc++-dev
- libstdc++-4.8-dev
-
env: CXX_COMPILER=clang++-3.6 CC_COMPILER=clang-3.6 BUILD_TYPE=Release WITH_FFMPEG=ON WITH_FFMPEG_JOBS=1
+1
View File
@@ -386,6 +386,7 @@ else() # Linux
sm_add_compile_flag("${SM_EXE_NAME}" "-stdlib=libc++")
set_target_properties("${SM_EXE_NAME}"
PROPERTIES LINK_FLAGS "-stdlib=libc++")
sm_add_compile_flag("jsoncpp" "-stdlib=libc++")
endif()
endif()
+7 -1
View File
@@ -382,7 +382,13 @@ public:
/** @brief Allow a quick way to swap notedata. */
namespace std
{
template<> inline void swap<NoteData>( NoteData &nd1, NoteData &nd2 ){ nd1.swap( nd2 ); }
template<> inline void swap<NoteData>( NoteData &nd1, NoteData &nd2 )
#if !defined(_MSC_VER)
noexcept(is_nothrow_move_constructible<NoteData>::value && is_nothrow_move_assignable<NoteData>::value)
#endif
{
nd1.swap( nd2 );
}
}
#endif
+12 -10
View File
@@ -1,6 +1,8 @@
#ifndef ARCH_HOOKS_H
#define ARCH_HOOKS_H
#include <ctime>
struct lua_State;
class ArchHooks
{
@@ -41,7 +43,7 @@ public:
/**
* @brief Setup the rendering threads for concurrency.
*
*
* The priority of the concurrent rendering thread may need to be boosted
* on some schedulers.
*/
@@ -52,7 +54,7 @@ public:
* @return true if the user wants to quit, false otherwise. */
static bool UserQuit() { return g_bQuitting; }
static void SetUserQuit() { g_bQuitting = true; }
/*
* Returns true if the user wants to toggle windowed mode and atomically clears
* the boolean.
@@ -86,13 +88,13 @@ public:
*/
static int64_t GetMicrosecondsSinceStart( bool bAccurate );
/*
* Add file search paths, higher priority first.
/*
* Add file search paths, higher priority first.
*/
static void MountInitialFilesystems( const RString &sDirOfExecutable );
/*
* Add file search paths for user-writable directories.
/*
* Add file search paths for user-writable directories.
*/
static void MountUserFilesystems( const RString &sDirOfExecutable );
@@ -117,10 +119,10 @@ public:
virtual bool GoToURL( RString sUrl );
virtual float GetDisplayAspectRatio() = 0;
/** @brief Fetch the contents of the system clipboard. */
virtual RString GetClipboard();
// Lua
void PushSelf( lua_State *L );
void RegisterWithLua();
@@ -146,7 +148,7 @@ extern ArchHooks *HOOKS; // global and accessible from anywhere in our program
* @author Glenn Maynard, Chris Danford (c) 2003-2004
* @section LICENSE
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -156,7 +158,7 @@ extern ArchHooks *HOOKS; // global and accessible from anywhere in our program
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+20 -10
View File
@@ -46,18 +46,28 @@ extern "C" void __assert_perror_fail( int errnum, const char *file, unsigned int
/* Catch unhandled C++ exceptions. Note that this works in g++ even with -fno-exceptions, in
* which case it'll be called if any exceptions are thrown at all. */
#include <cxxabi.h>
void UnexpectedExceptionHandler()
{
type_info *pException = abi::__cxa_current_exception_type();
char const *pName = pException->name();
int iStatus = -1;
char *pDem = abi::__cxa_demangle( pName, 0, 0, &iStatus );
const RString error = ssprintf("Unhandled exception: %s", iStatus? pName:pDem);
std::exception_ptr exptr = std::current_exception();
try
{
std::rethrow_exception(exptr);
}
catch (std::exception &ex)
{
#if defined(CRASH_HANDLER)
sm_crash( error );
const RString error = ssprintf("Unhandled exception: %s", ex.what());
sm_crash( error );
#endif
}
// TODO: Don't throw anything not subclassing std::exception
catch(...)
{
#if defined(CRASH_HANDLER)
const RString error = ssprintf("Unknown exception.");
sm_crash( error );
#endif
}
}
void InstallExceptionHandler()
@@ -68,7 +78,7 @@ void InstallExceptionHandler()
/*
* (c) 2003-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -78,7 +88,7 @@ void InstallExceptionHandler()
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF