Skip to content

Commit de8f974

Browse files
committed
use source_location correctly
1 parent bf8717d commit de8f974

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

test/iso_fortran_binding/sampling.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
#include <source_location>
1515
#endif
1616

17+
#if __has_include(<format>)
18+
#include <format>
19+
#endif
20+
1721
#include <ISO_Fortran_binding.h>
1822

1923

24+
void check_cfi(int
25+
#if defined(__cpp_lib_source_location)
26+
, const std::source_location& = std::source_location::current()
27+
#endif
28+
);
29+
2030

2131
static const std::vector<std::string> cfi_errstrs = {
2232
"No error detected.",
@@ -54,16 +64,22 @@ std::string cfiGetErrorString(int stat) {
5464
return cfi_errstrs[11];
5565
}
5666

57-
void check_cfi(int s)
58-
{
59-
if (s != CFI_SUCCESS){
67+
void check_cfi(int src
6068
#if defined(__cpp_lib_source_location)
61-
constexpr std::source_location loc = std::source_location::current();
62-
std::cerr << loc.file_name() << ":" << loc.line() <<
69+
, const std::source_location& location){
70+
std::string s =
71+
#if defined(__cpp_lib_format)
72+
std::format("{}:{}", location.file_name(), location.line());
73+
#else
74+
std::string(location.file_name()) + ":" + std::to_string(location.line());
75+
#endif
6376
#else
64-
std::cerr <<
77+
){
78+
std::string_view s;
6579
#endif
66-
" CFI API failed with error: (" << s << ") " << cfiGetErrorString(s) << "\n";
80+
81+
if (src != CFI_SUCCESS){
82+
std::cerr <<" CFI API failed " << s << " with error: (" << src << ") " << cfiGetErrorString(src) << "\n";
6783
}
6884
}
6985

0 commit comments

Comments
 (0)