Skip to content

Commit 437956c

Browse files
committed
use C++20
1 parent 8da5a57 commit 437956c

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

cmake/abi_check/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set_property(TARGET addone_f PROPERTY Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_B
1919
target_include_directories(addone_f PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
2020

2121
add_executable(main_cpp main.cpp $<TARGET_OBJECTS:addone_f>)
22+
target_compile_features(main_cpp PUBLIC cxx_std_17)
2223
add_test(NAME Cpp_main COMMAND main_cpp)
2324

2425
add_executable(main_c main.c $<TARGET_OBJECTS:addone_f>)

cmake/abi_check/addtwo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#include "myadd.h"
22

3-
int addtwo(int N){
4-
return N + 2;
5-
}
3+
int addtwo(int N){ return N + 2; }

cmake/abi_check/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
int main() {
77

8-
int i = addone(2);
9-
10-
if(i != 3) {
8+
if(int i = addone(2); i != 3) {
119
std::cerr << "2 + 1 != " << i << "\n";
1210
return EXIT_FAILURE;
1311
}

test/iso_fortran_binding/sampling.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@
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

4954
void 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

5562
template<typename Action>
@@ -71,7 +78,7 @@ class final_action
7178
template< 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

Comments
 (0)