Commit f3926560 authored by Imdad Sardharwalla's avatar Imdad Sardharwalla Committed by GitHub Enterprise
Browse files

REFORM-965 Update to C++17 (except on macOS) (#15)

This applies only to Windows and Linux builds. On macOS, there is a lack of support
for C++17 standard library features in XCode10, and so builds here are set to use
C++14 and the Boost libraries.

* Replace boost::filesystem and boost::system::error_code with std::filesystem and
  std::error_code.
  
* Replace std::uncaught_exception() with std::uncaught_exceptions().
parent ff50322c
......@@ -44,9 +44,16 @@ target_include_directories(${output_lib} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/.."
# set_target_properties(${output_lib} PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(${output_lib} PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(${output_lib} PROPERTIES C_STANDARD 99)
set_target_properties(${output_lib} PROPERTIES CXX_STANDARD 14)
set_target_properties(${output_lib} PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Set C++ version to 14 if on macOS (as XCode10 does not support enough of C++17)
# and 17 otherwise.
if (APPLE)
set_target_properties(${output_lib} PROPERTIES CXX_STANDARD 14)
else (APPLE)
set_target_properties(${output_lib} PROPERTIES CXX_STANDARD 17)
endif (APPLE)
if (MSVC)
add_definitions(/W4) # warnings at level 4
endif (MSVC)
......@@ -19,23 +19,22 @@
#include <set>
#include <algorithm>
#ifdef JOURNAL_USE_BOOST
#ifdef __APPLE__
# ifndef JOURNAL_USE_BOOST
# error Boost is required for journaling on macOS.
# endif
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#else // JOURNAL_USE_BOOST
// filesystem uses memcpy() in MSVC, suppress warnings
INSECURE_INCLUDE_SECTION_BEGIN
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#else // __APPLE__
// Include <filesystem> but silence resulting C4995 warnings
INSECURE_INCLUDE_SECTION_BEGIN
#include <filesystem>
INSECURE_INCLUDE_SECTION_END
namespace fs = std::experimental::filesystem;
#endif // JOURNAL_USE_BOOST
namespace fs = std::filesystem;
#endif // __APPLE__
namespace Journal {
......@@ -97,7 +96,11 @@ bool make_directory(String& _path)
};
// store existing journal folders ordered by time and then lexicographically
#ifdef __APPLE__
typedef std::pair<std::time_t, fs::path> TimePath;
#else // __APPLE__
typedef std::pair<fs::file_time_type, fs::path> TimePath;
#endif // __APPLE__
std::set<TimePath> fldrs;
fs::path path; // try to find a journal folder that does not exist yet
......@@ -108,24 +111,18 @@ bool make_directory(String& _path)
break;
// path exists, store it together with the last write time
auto time = fs::last_write_time(path);
fldrs.emplace(
#ifdef JOURNAL_USE_BOOST
time,
#else // JOURNAL_USE_BOOST
decltype(time)::clock::to_time_t(time),
#endif // JOURNAL_USE_BOOST
path);
fldrs.emplace(time, path);
}
if (fs::exists(path)) // all journal folders are already used
{// try to remove the oldest of the existing folders
for (const auto& fldr : fldrs) // iterate starting with the oldest path
{
#ifdef JOURNAL_USE_BOOST
#ifdef __APPLE__
boost::system::error_code err_code;
#else // JOURNAL_USE_BOOST
#else // __APPLE__
std::error_code err_code;
#endif // JOURNAL_USE_BOOST
#endif // __APPLE__
path = fldr.second;
const fs::path path_tmpr(path.string() + "-tmpr");
fs::rename(path, path_tmpr, err_code);
......@@ -188,12 +185,12 @@ String extract_directory(const String& _path)
String replace_filename(const String& _path, const String& _flnm)
{
fs::path path(_path);
#ifdef JOURNAL_USE_BOOST
#ifdef __APPLE__
path.remove_filename();
path /= _flnm;
#else
#else // __APPLE__
path.replace_filename(_flnm);
#endif//JOURNAL_USE_BOOST
#endif // __APPLE__
return path.string();
}
......
......@@ -63,7 +63,13 @@ void Context::abort()
// https://akrzemi1.wordpress.com/2011/09/21/destructors-that-throw/
// But we rather just wait until the current exception is handled.
if (!abrt_alwd_ || std::uncaught_exception())
if (!abrt_alwd_ ||
#ifdef __APPLE__
std::uncaught_exception()
#else // __APPLE__
std::uncaught_exceptions()
#endif // __APPLE__
)
return;
abrt_stte_ = AST_PROCESSING;
BASE_THROW_ERROR(PROGRESS_ABORTED);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment