Skip to content

Commit 87b4162

Browse files
committed
accomodate GCC < 10
1 parent 0b10bce commit 87b4162

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

cmake/compilers.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ add_compile_options(
170170
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-fno-backtrace>"
171171
)
172172

173+
add_compile_options("$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,10.0>>:-Wno-attributes>")
174+
# this is for UNLIKELY/LIKELY macros
175+
173176
# "$<$<COMPILE_LANGUAGE:Fortran>:-Werror=array-bounds;-fcheck=all>"
174177

175178
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")

src/uid/uid.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
#include "uid.h"
2020

21+
#if __has_attribute(unlikely)
22+
#define UNLIKELY [[unlikely]]
23+
#else
24+
#define UNLIKELY
25+
#endif
26+
2127

2228
extern "C" {
2329
std::string::size_type c_get_uid(char* result, const std::string::size_type buffer_size) {
@@ -27,7 +33,7 @@ std::string::size_type c_get_uid(char* result, const std::string::size_type buff
2733

2834
std::string::size_type str2char(std::string_view s, char* result, const std::string::size_type buffer_size)
2935
{
30-
if(s.length() >= buffer_size) [[unlikely]]
36+
if(s.length() >= buffer_size) UNLIKELY
3137
{
3238
std::cerr << "ERROR: " << s << " " << std::make_error_code(std::errc::result_out_of_range) << "\n";
3339
return 0;

0 commit comments

Comments
 (0)