Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to allow compilation with gcc 6 #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we do throws all over the place, I'm REALLY curious what makes this throw different than the other throws:

jeffcof:code> grep -R throw | grep -v \\throws | grep -v // | wc -l
685
jeffcof:code> 

So not counting SCX or other providers, JUST the PAL, what makes this throw different from 684 other throws?

Please research this, I'd prefer fixing the code than masking the error if we can. Otherwise looks fine.

Will mark awaiting feedback to see what you determine here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment to explain. They are thorwing in a destructor, very poor practice. If the throw ever occurs it will panic the app

}
#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean readdir_r?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we treat warnings as errors in debug mode?

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