Skip to content

Commit 02c3f95

Browse files
committed
add workaround for msvc constexpr init issue (closes #8)
1 parent 83940c0 commit 02c3f95

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

.github/workflows/windows.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: windows
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: windows-2022
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
build-type: [ Release, Debug ]
12+
compiler: [
13+
{ name: msvc, toolset: v143 },
14+
{ name: clang, toolset: ClangCL }
15+
]
16+
17+
defaults:
18+
run:
19+
working-directory: ${{ github.workspace }}/build
20+
21+
name: ${{ matrix.compiler.name }}-${{ matrix.build-type }}
22+
23+
24+
steps:
25+
- name: checkout-repo
26+
uses: actions/checkout@v4
27+
28+
- name: setup-catch
29+
env:
30+
CMAKE_GENERATOR: "Visual Studio 17 2022"
31+
CMAKE_GENERATOR_TOOLSET: ${{ matrix.compiler.toolset }}
32+
CMAKE_GENERATOR_PLATFORM: ${{ matrix.platform }}
33+
run: bash ../tools/install_catch.sh ${{ matrix.build-type }}
34+
35+
- name: setup-build
36+
env:
37+
CMAKE_GENERATOR: "Visual Studio 17 2022"
38+
CMAKE_GENERATOR_TOOLSET: ${{ matrix.compiler.toolset }}
39+
CMAKE_GENERATOR_PLATFORM: ${{ matrix.platform }}
40+
run: cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DSMP_BUILD_BENCHMARKS=OFF
41+
42+
- name: build
43+
run: cmake --build . --parallel --config ${{ matrix.build-type }}
44+
45+
- name: run-tests
46+
run: ctest --output-on-failure --schedule-random

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.hint
77

88
.cache/
9+
out/

src/small_unique_ptr.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace smp::detail
2525
template<std::integral T>
2626
constexpr T max_pow2_factor(T n) noexcept { return n & (~n + 1); }
2727

28+
template<typename T, typename U, std::size_t N>
29+
constexpr const void fill(T(&arr)[N], U value)
30+
{
31+
for (std::size_t i = 0; i < N; i++)
32+
arr[i] = value;
33+
}
2834

2935
struct ignore_t
3036
{
@@ -163,6 +169,14 @@ namespace smp::detail
163169
using pointer = std::remove_cv_t<T>*;
164170
using buffer_t = unsigned char[buffer_size_v<T, Size>];
165171

172+
constexpr small_unique_ptr_base() noexcept
173+
{
174+
if (std::is_constant_evaluated())
175+
{
176+
detail::fill(buffer_, 0);
177+
}
178+
}
179+
166180
pointer buffer(std::ptrdiff_t offset = 0) const noexcept
167181
{
168182
assert(offset <= sizeof(buffer_t));
@@ -234,6 +248,14 @@ namespace smp::detail
234248
using pointer = std::remove_cv_t<T>*;
235249
using buffer_t = unsigned char[buffer_size_v<T, Size>];
236250

251+
constexpr small_unique_ptr_base() noexcept
252+
{
253+
if (std::is_constant_evaluated())
254+
{
255+
detail::fill(buffer_, 0);
256+
}
257+
}
258+
237259
pointer buffer(std::ptrdiff_t offset = 0) const noexcept
238260
{
239261
assert(offset <= sizeof(buffer_t));

0 commit comments

Comments
 (0)