Skip to content

Commit aaabc01

Browse files
committed
make it compiles with C++17/20/23
1 parent 62b0b9f commit aaabc01

File tree

14 files changed

+98
-42
lines changed

14 files changed

+98
-42
lines changed

.github/workflows/ci.linux.arm.yml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
branches: [ "main", "release/*" ]
88

99
jobs:
10-
gcc921:
11-
runs-on: [self-hosted, Linux, ARM64]
10+
arm-linux-build-and-test:
11+
runs-on: ubuntu-24.04-arm
1212

1313
container:
1414
image: ghcr.io/alibaba/photon-ut-base:latest
@@ -23,7 +23,7 @@ jobs:
2323

2424
- uses: actions/checkout@v4
2525

26-
- name: Build
26+
- name: Build-Debug-921-C++14
2727
run: |
2828
source /opt/rh/gcc-toolset-9/enable
2929
cmake -B build \
@@ -36,31 +36,42 @@ jobs:
3636
-D PHOTON_ENABLE_EXTFS=ON
3737
cmake --build build -j $(nproc) -- VERBOSE=1
3838
39-
- name: Test
39+
- name: Build-Debug-921-C++17
4040
run: |
41-
cd build
42-
ctest -E test-lockfree --timeout 3600 -V
43-
44-
gcc921-build-debug:
45-
runs-on: [self-hosted, Linux, ARM64]
46-
47-
container:
48-
image: ghcr.io/alibaba/photon-ut-base:latest
49-
options: --cpus 4
50-
51-
steps:
52-
- uses: szenius/set-timezone@v2.0
53-
with:
54-
timezoneLinux: "Asia/Shanghai"
55-
timezoneMacos: "Asia/Shanghai"
56-
timezoneWindows: "China Standard Time"
41+
source /opt/rh/gcc-toolset-9/enable
42+
rm -fr build
43+
cmake -B build \
44+
-D PHOTON_CXX_STANDARD=17 \
45+
-D CMAKE_BUILD_TYPE=Debug \
46+
-D PHOTON_ENABLE_ECOSYSTEM=ON \
47+
-D PHOTON_BUILD_TESTING=ON \
48+
-D PHOTON_ENABLE_SASL=ON \
49+
-D PHOTON_ENABLE_FUSE=ON \
50+
-D PHOTON_ENABLE_LIBCURL=ON \
51+
-D PHOTON_ENABLE_EXTFS=ON
52+
cmake --build build -j $(nproc) -- VERBOSE=1
5753
58-
- uses: actions/checkout@v4
54+
- name: Build-Debug-1121-C++20
55+
run: |
56+
source /opt/rh/gcc-toolset-11/enable
57+
rm -fr build
58+
cmake -B build \
59+
-D PHOTON_CXX_STANDARD=20 \
60+
-D CMAKE_BUILD_TYPE=Debug \
61+
-D PHOTON_ENABLE_ECOSYSTEM=ON \
62+
-D PHOTON_BUILD_TESTING=ON \
63+
-D PHOTON_ENABLE_SASL=ON \
64+
-D PHOTON_ENABLE_FUSE=ON \
65+
-D PHOTON_ENABLE_LIBCURL=ON \
66+
-D PHOTON_ENABLE_EXTFS=ON
67+
cmake --build build -j $(nproc) -- VERBOSE=1
5968
60-
- name: Build
69+
- name: Build-Debug-1211-C++23
6170
run: |
62-
source /opt/rh/gcc-toolset-9/enable
71+
source /opt/rh/gcc-toolset-12/enable
72+
rm -fr build
6373
cmake -B build \
74+
-D PHOTON_CXX_STANDARD=23 \
6475
-D CMAKE_BUILD_TYPE=Debug \
6576
-D PHOTON_ENABLE_ECOSYSTEM=ON \
6677
-D PHOTON_BUILD_TESTING=ON \
@@ -69,3 +80,8 @@ jobs:
6980
-D PHOTON_ENABLE_LIBCURL=ON \
7081
-D PHOTON_ENABLE_EXTFS=ON
7182
cmake --build build -j $(nproc) -- VERBOSE=1
83+
84+
- name: Test
85+
run: |
86+
cd build
87+
ctest -E test-lockfree --timeout 3600 -V

common/consistent-hash-map.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class consistent_hash_map
5555
const allocator_type& alloc = allocator_type()) :
5656
m_comp(comp), m_vector(alloc) { }
5757

58-
using reference = typename allocator_type::reference;
59-
using const_reference = typename allocator_type::const_reference;
60-
using pointer = typename allocator_type::pointer;
61-
using const_pointer = typename allocator_type::const_pointer;
58+
using reference = mapped_type&;
59+
using const_reference = const mapped_type&;
60+
using pointer = mapped_type*;
61+
using const_pointer = const mapped_type*;
6262
using container_type = std::vector<value_type, allocator_type>;
6363
using iterator = typename container_type::iterator;
6464
using const_iterator = typename container_type::const_iterator;

common/enumerable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ struct Enumerable
4141
if (obj && !obj->valid())
4242
this->obj = nullptr;
4343
}
44+
#if __cplusplus < 201703L
4445
using R = typename std::result_of<decltype(&T::get)(T)>::type;
46+
#else
47+
using R = typename std::invoke_result<decltype(&T::get), T>::type;
48+
#endif
49+
4550
R operator*() { return obj ? obj->get() : R{}; }
4651
bool operator==(const iterator& rhs) const { return obj == rhs.obj; }
4752
bool operator!=(const iterator& rhs) const { return !(*this == rhs); }

common/executor/executor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class Executor {
4141

4242
template <
4343
typename Context = AutoContext, typename Func,
44+
#if __cplusplus < 201703L
4445
typename R = typename std::result_of<Func()>::type,
46+
#else
47+
typename R = typename std::invoke_result<Func>::type,
48+
#endif
4549
typename _ = typename std::enable_if<!std::is_void<R>::value, R>::type>
4650
R perform(Func &&act) {
4751
R result;
@@ -60,7 +64,11 @@ class Executor {
6064

6165
template <
6266
typename Context = AutoContext, typename Func,
67+
#if __cplusplus < 201703L
6368
typename R = typename std::result_of<Func()>::type,
69+
#else
70+
typename R = typename std::invoke_result<Func>::type,
71+
#endif
6472
typename _ = typename std::enable_if<std::is_void<R>::value, R>::type>
6573
void perform(Func &&act) {
6674
Awaiter<Context> aop;

common/expirecontainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,4 @@ class ObjectCache<KeyType, intrusive_list<NodeType>>
463463
Base::release(typename Base::Item(key), recycle, destroy));
464464
}
465465
};
466+

common/test/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ TEST(iovector, test1)
507507
EXPECT_EQ(iov.sum(), 0);
508508
EXPECT_TRUE(iov.empty());
509509
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve);
510-
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve);
510+
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve);
511511
EXPECT_EQ(iov.begin(), iov.iovec());
512512

513513
iovec v{nullptr, 33}, v2{nullptr, 44};
@@ -523,7 +523,7 @@ TEST(iovector, test1)
523523
EXPECT_EQ(iov.back(), v);
524524
EXPECT_EQ(iov.iovcnt(), 3);
525525
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve - 3);
526-
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve);
526+
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve);
527527
EXPECT_EQ(iov.sum(), 44+55+33);
528528

529529
iov.push_back(77);
@@ -538,7 +538,7 @@ TEST(iovector, test1)
538538
EXPECT_EQ(iov.back(), v);
539539
EXPECT_EQ(iov.iovcnt(), 6);
540540
EXPECT_EQ(iov.front_free_iovcnt(), IOVector::default_preserve - 3);
541-
EXPECT_EQ(iov.back_free_iovcnt(), IOVector::capacity - IOVector::default_preserve - 3);
541+
EXPECT_EQ(iov.back_free_iovcnt(), (uint16_t)IOVector::capacity - (uint16_t)IOVector::default_preserve - 3);
542542
EXPECT_EQ(iov.sum(), 44+55+33 + 77+44+33);
543543

544544
EXPECT_EQ(iov.pop_front(), 44);

common/test/test_objcache.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ limitations under the License.
2222

2323
#undef private
2424
#undef protected
25+
2526
#include <thread>
2627
#include <gtest/gtest.h>
2728
#include <photon/thread/thread.h>

common/timeout.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ limitations under the License.
1515
*/
1616

1717
#pragma once
18-
#include <chrono>
1918
#include <cinttypes>
2019
#include <photon/common/utility.h>
20+
#ifdef private
21+
#define _PHOTON_UNIT_TEST
22+
#undef private
23+
#undef protected
24+
#endif
25+
#include <chrono>
26+
#ifdef _PHOTON_UNIT_TEST
27+
#undef _PHOTON_UNIT_TEST
28+
#define private public
29+
#define protected public
30+
#endif
2131

2232
namespace photon {
2333

examples/sync-primitive/sync-primitive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ int main() {
7777
message.sem.wait(1);
7878
auto end = std::chrono::steady_clock::now();
7979
auto duration_us = std::chrono::duration_cast<std::chrono::nanoseconds>(end - message.start).count();
80-
latency.fetch_add(duration_us, std::memory_order::memory_order_relaxed);
81-
qps.fetch_add(1, std::memory_order::memory_order_relaxed);
80+
latency.fetch_add(duration_us, std::memory_order_relaxed);
81+
qps.fetch_add(1, std::memory_order_relaxed);
8282
}
8383
}));
8484
}

fs/async_filesystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ namespace fs
8585
{
8686
public:
8787
template<typename IF, typename Func, typename...ARGS,
88+
#if __cplusplus < 201703L
8889
typename R = typename std::result_of<Func(IF*, ARGS...)>::type >
90+
#else
91+
typename R = typename std::invoke_result<Func, IF*, ARGS...>::type>
92+
#endif
8993
R perform(IF* _if, Func func, ARGS...args)
9094
{
9195
return th_performer<R>().call(_if, func, args...);

0 commit comments

Comments
 (0)