diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c54a47..eaafbc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,12 +34,20 @@ endif() if(PROJECT_IS_TOP_LEVEL) if(CMAKE_GENERATOR STREQUAL "Ninja") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fdiagnostics-color=always HAS_CXX_FDIAGNOSTICS_COLOR) + if(HAS_CXX_FDIAGNOSTICS_COLOR) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") + endif() elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") endif() if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always") + include(CheckCCompilerFlag) + check_c_compiler_flag(-fdiagnostics-color=always HAS_C_FDIAGNOSTICS_COLOR) + if(HAS_C_FDIAGNOSTICS_COLOR) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always") + endif() elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics") endif() @@ -176,6 +184,11 @@ target_compile_options( ${warning_options} ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + # https://godbolt.org/z/qYh89E6rq + target_compile_options(${target_name} PRIVATE -Wno-missing-field-initializers) +endif() + set(CPPTRACE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) set(CPPTRACE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) set(CPPTRACE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) diff --git a/src/binary/elf.cpp b/src/binary/elf.cpp index 19a438f..1117f13 100644 --- a/src/binary/elf.cpp +++ b/src/binary/elf.cpp @@ -424,7 +424,7 @@ namespace detail { static std::unordered_map> cache; auto it = cache.find(object_path); if(it == cache.end()) { - auto res = cache.insert({ object_path, elf::open_elf(object_path) }); + auto res = cache.emplace(object_path, elf::open_elf(object_path)); VERIFY(res.second); it = res.first; } diff --git a/src/from_current.cpp b/src/from_current.cpp index d099a76..6ffce4e 100644 --- a/src/from_current.cpp +++ b/src/from_current.cpp @@ -272,7 +272,8 @@ namespace cpptrace { memcpy(new_vtable_page, type_info_vtable_pointer, vtable_size * sizeof(void*)); // ninja in the custom __do_catch interceptor auto new_vtable = static_cast(new_vtable_page); - new_vtable[6] = reinterpret_cast(do_catch_function); + // double cast is done here because older (and some newer gcc versions) warned about it under -Wpedantic + new_vtable[6] = reinterpret_cast(reinterpret_cast(do_catch_function)); // make the page read-only mprotect_page(new_vtable_page, page_size, memory_readonly); diff --git a/src/symbols/dwarf/dwarf_resolver.cpp b/src/symbols/dwarf/dwarf_resolver.cpp index 0aee279..782ae43 100644 --- a/src/symbols/dwarf/dwarf_resolver.cpp +++ b/src/symbols/dwarf/dwarf_resolver.cpp @@ -324,7 +324,7 @@ namespace libdwarf { char** dw_srcfiles; Dwarf_Signed dw_filecount; VERIFY(wrap(dwarf_srcfiles, cu_die.get(), &dw_srcfiles, &dw_filecount) == DW_DLV_OK); - it = srcfiles_cache.insert(it, {off, srcfiles{cu_die.dbg, dw_srcfiles, dw_filecount}}); + it = srcfiles_cache.emplace_hint(it, off, srcfiles{cu_die.dbg, dw_srcfiles, dw_filecount}); } if(file_i < it->second.count()) { // dwarf is using 1-indexing diff --git a/src/symbols/dwarf/dwarf_utils.hpp b/src/symbols/dwarf/dwarf_utils.hpp index 56a46e5..7676ddb 100644 --- a/src/symbols/dwarf/dwarf_utils.hpp +++ b/src/symbols/dwarf/dwarf_utils.hpp @@ -67,7 +67,14 @@ namespace libdwarf { // sorted range entries for dies template< typename T, - typename std::enable_if::value && sizeof(T) <= 16, int>::type = 0 + typename std::enable_if< + // old gcc doesn't support this trait https://godbolt.org/z/fKWT9jTK7 + #if !(defined(__GNUC__) && (__GNUC__ < 5)) + std::is_trivially_copyable::value && + #endif + sizeof(T) <= 16, + int + >::type = 0 > class die_cache { public: diff --git a/src/utils/common.hpp b/src/utils/common.hpp index 954f694..b99001c 100644 --- a/src/utils/common.hpp +++ b/src/utils/common.hpp @@ -24,6 +24,13 @@ #define NODISCARD #endif +// workaround a bizarre gcc bug https://godbolt.org/z/s78vnf7jv +// https://github.com/jeremy-rifkin/cpptrace/issues/220 +#if defined(__GNUC__) && (__GNUC__ < 7) + #undef NODISCARD + #define NODISCARD +#endif + #if IS_MSVC #define MSVC_CDECL __cdecl #else