Skip to content

Commit

Permalink
Changes to allow compilation with gcc 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Campbell committed Dec 20, 2016
1 parent fe4604b commit 4b0f3d6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/Makefile.gcc4
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#--------------------------------------------------------------------------------

include $(SCX_BRD)/build/Makefile.gcc3
CXX_WARN_FLAGS+=-Wstrict-null-sentinel -Wmissing-include-dirs -Winit-self -Wextra
CXX_WARN_FLAGS+=-Wstrict-null-sentinel -Wmissing-include-dirs -Winit-self -Wextra

ifeq ($(PF_DISTRO)$(PF_MAJOR),SUSE11)
CXX_WARN_FLAGS+=-Wno-ignored-qualifiers
Expand Down
3 changes: 3 additions & 0 deletions build/Makefile.pf.Linux
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ else
include Makefile.gcc4
endif

# Needed for compat with Gcc 6 and beyond
CXXFLAGS += -std=gnu++98

# C++ 11 for IBM atomic support
ifeq ($(ARCH),ppc)
CXXFLAGS += -std=c++11 -D=linux
Expand Down
14 changes: 14 additions & 0 deletions source/code/scxcorelib/pal/scxcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ namespace SCXCoreLib
SCXCondition::~SCXCondition()
{
#if defined(SCX_UNIX)
#if __GNUC__ >= 6
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wc++11-compat"
#endif

// BUG ALERT!!!!
// Destructors are noexcept by default in C++11. Throwing an exception from a destructor or constructor
// is always poor practice because it leaves the object in an undefrined state, neither constructed or destructed.
// In this case, the best case would be a memory leak. The gcc 6 and after will treat this as an error and it will
// always abort the program.

int err;
if (0 != (err = pthread_cond_destroy(&m_cond)))
{
Expand All @@ -94,6 +105,9 @@ namespace SCXCoreLib
{
throw SCXErrnoException(L"pthread_mutex_destroy() function call failed", err, SCXSRCLOCATION);
}
#if __GNUC__ >= 6
#pragma GCC diagnostic pop
#endif
#elif defined(WIN32)
DeleteCriticalSection(&m_lock);

Expand Down
8 changes: 8 additions & 0 deletions source/code/scxcorelib/pal/scxdirectoryinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,15 @@ namespace
#if defined(sun)
while (NULL != (dentp = readdir_r(dirp, currentDir))) {
#else
#if (__GNUC__ >= 6 )
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#endif
// readdir_c is deprecated as of POSIX 1.2008 but is still supported and not simple to implement the recommended usage. Make a warning for now
while ((0 == readdir_r(dirp, currentDir, &dentp)) && NULL != dentp) {
#if (__GNUC__ >= 6)
#pragma GCC diagnostic pop
#endif
#endif
bool isdir = false; // Is this a directory entry
SCXCoreLib::SCXFileSystem::SCXStatStruct* pStat = 0;
Expand Down
2 changes: 1 addition & 1 deletion source/code/scxcorelib/util/scxmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace SCXCoreLib
scxlong RoundToScxLong(double value)
{
double roundedValue = Round(value);
if (cMinScxLong <= roundedValue && roundedValue <= cMaxScxLong) {
if ((double)cMinScxLong <= roundedValue && roundedValue <= (double)cMaxScxLong) {
return static_cast<scxlong> (roundedValue);
} else {
throw SCXInvalidArgumentException(L"value", L"Value of double outside the range of long",
Expand Down

0 comments on commit 4b0f3d6

Please sign in to comment.