77#include < span>
88#include < ranges>
99#include < algorithm>
10+ #include < vector>
11+ #include < string>
12+ #include < source_location>
1013
1114#include < ISO_Fortran_binding.h>
1215
13- static const char *cfi_errstrs[12 ] = {
14- " No error detected.\n " ,
15- " The base address member of a C descriptor is a null pointer in a context that requires a non-null pointer value.\n " ,
16- " The base address member of a C descriptor is not a null pointer in a context that requires a null pointer value.\n " ,
17- " The value supplied for the element length member of a C descriptor is not valid.\n " ,
18- " The value supplied for the rank member of a C descriptor is not valid.\n " ,
19- " The value supplied for the type member of a C descriptor is not valid.\n " ,
20- " The value supplied for the attribute member of a C descriptor is not valid.\n " ,
21- " The value supplied for the extent member of a CFI_dim_t structure is not valid.\n " ,
22- " A C descriptor is invalid in some way.\n " ,
23- " Memory allocation failed.\n " ,
24- " A reference is out of bounds.\n " ,
25- " Unrecognized status code.\n "
16+
17+
18+ static const std::vector<std::string> cfi_errstrs = {
19+ " No error detected." ,
20+ " The base address member of a C descriptor is a null pointer in a context that requires a non-null pointer value." ,
21+ " The base address member of a C descriptor is not a null pointer in a context that requires a null pointer value." ,
22+ " The value supplied for the element length member of a C descriptor is not valid." ,
23+ " The value supplied for the rank member of a C descriptor is not valid." ,
24+ " The value supplied for the type member of a C descriptor is not valid." ,
25+ " The value supplied for the attribute member of a C descriptor is not valid." ,
26+ " The value supplied for the extent member of a CFI_dim_t structure is not valid." ,
27+ " A C descriptor is invalid in some way." ,
28+ " Memory allocation failed." ,
29+ " A reference is out of bounds." ,
30+ " Unrecognized status code."
2631};
2732
2833// Returns the description string for an error code.
2934//
30- const char * cfiGetErrorString (int stat) {
35+ std::string cfiGetErrorString (int stat) {
3136
3237 switch (stat) {
3338 case CFI_SUCCESS: return cfi_errstrs[0 ];
@@ -48,8 +53,10 @@ const char* cfiGetErrorString(int stat) {
4853
4954void check_cfi (int s)
5055{
51- if (s != CFI_SUCCESS)
52- std::cerr << __FILE__ << " :" << __LINE__ << " CFI API failed with error: (" << s << " ) " << cfiGetErrorString (s) << " \n " ;
56+ if (s != CFI_SUCCESS){
57+ 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 " ;
59+ }
5360}
5461
5562template <typename Action>
@@ -71,7 +78,7 @@ class final_action
7178template < class Fn >
7279[[nodiscard]] auto finally ( Fn const & f )
7380{
74- return final_action (( f ) );
81+ return final_action ( f );
7582}
7683
7784//
0 commit comments