Skip to content

Commit 94f1f02

Browse files
committed
fallback source_location
1 parent c90bb21 commit 94f1f02

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

test/iso_fortran_binding/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ add_executable(sampling sampling.cpp sampling.f90)
1717
set_property(TARGET sampling PROPERTY LINKER_LANGUAGE CXX)
1818

1919
add_test(NAME sampling COMMAND sampling)
20+
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 12)
21+
set_property(TEST sampling PROPERTY DISABLED true)
22+
endif()
2023
endif()
2124

2225
if(HAVE_CFI_IS_CONTIGUOUS)

test/iso_fortran_binding/sampling.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#include <algorithm>
1010
#include <vector>
1111
#include <string>
12+
13+
#if __has_include(<source_location>)
1214
#include <source_location>
15+
#endif
1316

1417
#include <ISO_Fortran_binding.h>
1518

@@ -54,8 +57,13 @@ std::string cfiGetErrorString(int stat) {
5457
void check_cfi(int s)
5558
{
5659
if (s != CFI_SUCCESS){
60+
#if defined(__cpp_lib_source_location)
5761
constexpr std::source_location loc = std::source_location::current();
58-
std::cerr << loc.file_name() << ":" << loc.line() << " CFI API failed with error: (" << s << ") " << cfiGetErrorString(s) << "\n";
62+
std::cerr << loc.file_name() << ":" << loc.line() <<
63+
#else
64+
std::cerr <<
65+
#endif
66+
" CFI API failed with error: (" << s << ") " << cfiGetErrorString(s) << "\n";
5967
}
6068
}
6169

@@ -163,5 +171,5 @@ int main(int argc, char const *argv[])
163171
std::cout << "pi = " << estimate_pi( N ) << '\n';
164172
std::cout << "pi = " << f_estimate_pi( N ) << '\n';
165173

166-
return 0;
174+
return EXIT_SUCCESS;
167175
}

0 commit comments

Comments
 (0)