Skip to content

Commit 731f9cf

Browse files
authored
Merge pull request #17 from simdutf/fix/build-with-cxx-20
Fix build with C++20
2 parents 97a6ed6 + 80d5428 commit 731f9cf

File tree

4 files changed

+84
-11
lines changed

4 files changed

+84
-11
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Ubuntu 22.04 CI (GCC 11, CXX 20)
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ubuntu-build:
7+
if: >-
8+
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
9+
! contains(toJSON(github.event.commits.*.message), '[skip github]')
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Use cmake
14+
run: |
15+
mkdir builddebug &&
16+
cd builddebug &&
17+
cmake -DCMAKE_BUILD_TYPE=Debug -DIS_UTF8_CXX_STANDARD=20 .. &&
18+
cmake --build . &&
19+
ctest -j --output-on-failure -LE explicitonly &&
20+
cd .. &&
21+
mkdir build &&
22+
cd build &&
23+
cmake -DIS_UTF8_CXX_STANDARD=20 .. &&
24+
cmake --build . &&
25+
ctest -j --output-on-failure -LE explicitonly

.github/workflows/vs17-cxx20.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: VS17-CI (CXX 20)
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ci:
7+
if: >-
8+
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
9+
! contains(toJSON(github.event.commits.*.message), '[skip github]')
10+
name: windows-vs17
11+
runs-on: windows-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- {gen: Visual Studio 17 2022, arch: x64, shared: ON}
17+
- {gen: Visual Studio 17 2022, arch: x64, shared: OFF}
18+
steps:
19+
- name: checkout
20+
uses: actions/checkout@v4
21+
- name: Configure
22+
run: >
23+
cmake -G "${{matrix.gen}}" -A ${{matrix.arch}}
24+
-DBUILD_SHARED_LIBS=${{matrix.shared}} -DIS_UTF8_CXX_STANDARD=20
25+
-B build
26+
- name: Build Debug
27+
run: cmake --build build --config Debug --verbose
28+
- name: Build Release
29+
run: cmake --build build --config Release --verbose
30+
- name: Run Release tests
31+
run: |
32+
cd build
33+
ctest -C Release -LE explicitonly --output-on-failure
34+
- name: Run Debug tests
35+
run: |
36+
cd build
37+
ctest -C Debug -LE explicitonly --output-on-failure

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ if (NOT CMAKE_BUILD_TYPE)
2020
endif()
2121
endif()
2222

23-
set(CMAKE_CXX_STANDARD 14)
23+
# We compile tools, tests, etc. with C++ 11. Override yourself if you need on a
24+
# target.
25+
set(IS_UTF8_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for is_utf8")
26+
27+
set(CMAKE_CXX_STANDARD ${IS_UTF8_CXX_STANDARD})
2428
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2529
set(CMAKE_CXX_EXTENSIONS OFF)
2630
set(CMAKE_MACOSX_RPATH OFF)
@@ -40,6 +44,8 @@ endif(BUILD_TESTING)
4044

4145

4246
add_subdirectory(benchmarks)
47+
48+
message(STATUS "Compiling using the C++ standard:" ${CMAKE_CXX_STANDARD})
4349
# ---- Install rules ----
4450
add_library(is_utf8::is_utf8 ALIAS is_utf8)
4551

src/is_utf8.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,9 @@ template <typename T, typename Mask = simd8<bool>> struct base_u8 {
11161116
return *this_cast;
11171117
}
11181118
1119-
is_utf8_really_inline Mask operator==(const simd8<T> other) const {
1120-
return vceqq_u8(*this, other);
1119+
friend is_utf8_really_inline Mask operator==(const simd8<T> lhs,
1120+
const simd8<T> rhs) {
1121+
return vceqq_u8(lhs, rhs);
11211122
}
11221123
11231124
template <int N = 1>
@@ -2539,8 +2540,9 @@ struct base8 : base<simd8<T>> {
25392540
is_utf8_really_inline T last() const {
25402541
return _mm256_extract_epi8(*this, 31);
25412542
}
2542-
is_utf8_really_inline Mask operator==(const simd8<T> other) const {
2543-
return _mm256_cmpeq_epi8(*this, other);
2543+
friend is_utf8_really_inline Mask operator==(const simd8<T> lhs,
2544+
const simd8<T> rhs) {
2545+
return _mm256_cmpeq_epi8(lhs, rhs);
25442546
}
25452547

25462548
static const int SIZE = sizeof(base<T>::value);
@@ -2965,8 +2967,9 @@ struct base16 : base<simd16<T>> {
29652967
is_utf8_really_inline base16(const Pointer *ptr)
29662968
: base16(_mm256_loadu_si256(reinterpret_cast<const __m256i *>(ptr))) {}
29672969

2968-
is_utf8_really_inline Mask operator==(const simd16<T> other) const {
2969-
return _mm256_cmpeq_epi16(*this, other);
2970+
friend is_utf8_really_inline Mask operator==(const simd16<T> lhs,
2971+
const simd16<T> rhs) {
2972+
return _mm256_cmpeq_epi16(lhs, rhs);
29702973
}
29712974

29722975
/// the size of vector in bytes
@@ -3517,8 +3520,9 @@ struct base8 : base<simd8<T>> {
35173520
is_utf8_really_inline base8() : base<simd8<T>>() {}
35183521
is_utf8_really_inline base8(const __m128i _value) : base<simd8<T>>(_value) {}
35193522

3520-
is_utf8_really_inline Mask operator==(const simd8<T> other) const {
3521-
return _mm_cmpeq_epi8(*this, other);
3523+
friend is_utf8_really_inline Mask operator==(const simd8<T> lhs,
3524+
const simd8<T> rhs) {
3525+
return _mm_cmpeq_epi8(lhs, rhs);
35223526
}
35233527

35243528
static const int SIZE = sizeof(base<simd8<T>>::value);
@@ -4032,8 +4036,9 @@ struct base16 : base<simd16<T>> {
40324036
is_utf8_really_inline base16(const Pointer *ptr)
40334037
: base16(_mm_loadu_si128(reinterpret_cast<const __m128i *>(ptr))) {}
40344038

4035-
is_utf8_really_inline Mask operator==(const simd16<T> other) const {
4036-
return _mm_cmpeq_epi16(*this, other);
4039+
friend is_utf8_really_inline Mask operator==(const simd16<T> lhs,
4040+
const simd16<T> rhs) {
4041+
return _mm_cmpeq_epi16(lhs, rhs);
40374042
}
40384043

40394044
static const int SIZE = sizeof(base<simd16<T>>::value);

0 commit comments

Comments
 (0)