-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 10139b4
Showing
12 changed files
with
972 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: sanitizers | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
sanitizer: [ address, undefined ] | ||
include: | ||
- cxx: clang++-15 | ||
pkgs: clang-15 llvm-15 | ||
|
||
env: | ||
ASAN_OPTIONS: check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:detect_leaks=1 | ||
UBSAN_OPTIONS: print_stacktrace=1:print_summary=1 | ||
|
||
defaults: | ||
run: | ||
working-directory: ${{ github.workspace }}/build | ||
|
||
|
||
name: ${{ matrix.cxx }} -fsanitize=${{ matrix.sanitizer }} | ||
|
||
steps: | ||
- name: checkout-repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: setup-compiler | ||
run: sudo apt update && sudo apt install -y ${{ matrix.pkgs }} | ||
|
||
- name: setup-dependencies | ||
env: | ||
CXX: ${{ matrix.cxx }} | ||
run: sudo bash ./install_catch.sh | ||
|
||
- name: setup-build | ||
env: | ||
CXX: ${{ matrix.cxx }} | ||
run: sudo cmake .. -DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }} -g -fno-omit-frame-pointer" | ||
|
||
- name: build | ||
run: sudo cmake --build . | ||
|
||
- name: run-tests | ||
run: sudo ctest --output-on-failure --schedule-random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# VSCode | ||
.vscode/ | ||
|
||
# Visual Studio | ||
.vs/ | ||
*.hint | ||
|
||
# Build results | ||
out/ | ||
build/* | ||
!build/*.sh | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(small_unique_ptr VERSION 0.1 LANGUAGES CXX) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build") | ||
|
||
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo)$") | ||
message(WARNING "The specified build type [${CMAKE_BUILD_TYPE}] is not recognized. Defaulting to Release.") | ||
set(CMAKE_BUILD_TYPE "Release") | ||
endif() | ||
|
||
if(MSVC) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -permissive- -W4 -WX -wd4324 -diagnostics:caret") | ||
else() | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror -pedantic-errors -g") | ||
endif() | ||
|
||
if(CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo)") | ||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) | ||
endif() | ||
|
||
add_library(small_unique_ptr INTERFACE) | ||
target_include_directories(small_unique_ptr SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") | ||
target_compile_features(small_unique_ptr INTERFACE "cxx_std_20") | ||
target_compile_options(small_unique_ptr INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:-Zc:preprocessor>" "$<$<CXX_COMPILER_ID:MSVC>:-Zc:__cplusplus>") | ||
|
||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "x64-Debug-msvc", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset", | ||
"enableMicrosoftCodeAnalysis": false, | ||
"inheritEnvironments": [ "msvc_x64_x64" ] | ||
}, | ||
{ | ||
"name": "x64-Release-msvc", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset", | ||
"enableMicrosoftCodeAnalysis": false, | ||
"inheritEnvironments": [ "msvc_x64_x64" ] | ||
}, | ||
{ | ||
"name": "x64-RelWithDebInfo-msvc", | ||
"generator": "Ninja", | ||
"configurationType": "RelWithDebInfo", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"codeAnalysisRuleset": "${projectDir}\\core-guidelines.ruleset", | ||
"enableMicrosoftCodeAnalysis": false, | ||
"inheritEnvironments": [ "msvc_x64_x64" ] | ||
}, | ||
{ | ||
"name": "x64-Debug-clang", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"inheritEnvironments": [ "clang_cl_x64_x64" ] | ||
}, | ||
{ | ||
"name": "x64-Release-clang", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"inheritEnvironments": [ "clang_cl_x64_x64" ] | ||
}, | ||
{ | ||
"name": "x64-RelWithDebInfo-clang", | ||
"generator": "Ninja", | ||
"configurationType": "RelWithDebInfo", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"ctestCommandArgs": "--output-on-failure --schedule-random", | ||
"inheritEnvironments": [ "clang_cl_x64_x64" ] | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Krisztián Rugási | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
A fully constexpr unique_ptr implementation in C++20 with small object optimization. | ||
|
||
Objects created with `make_unique_small<T>` are allocated on the stack if: | ||
|
||
- Their size is not greater than `cache_line_size - 2 * sizeof(void*)` | ||
- Their alignment is not greater than `cache_line_size` | ||
- Their move constructor is declared as `noexcept` | ||
|
||
The size of a `small_unique_ptr<T>` object is: | ||
|
||
- `cache_line_size` if T can be allocated in the stack buffer | ||
- `sizeof(T*)` otherwise | ||
|
||
The stack buffer is not used in constant evaluated contexts, so any constexpr usage | ||
is subject to the same transient allocation requirements that `std::unique_ptr<T>` would be. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
echo -e "Installing Catch2...\n" | ||
|
||
cmake --version | ||
|
||
BUILD_DIR=$(dirname $(realpath "$0"))/../build | ||
echo -e "\nThe build directory is ${BUILD_DIR}.\n" | ||
|
||
git clone -b v3.3.0 https://github.com/catchorg/Catch2.git $BUILD_DIR/Catch2 | ||
CATCH_BUILD_DIR=$BUILD_DIR/Catch2/build | ||
echo -e "\nThe Catch build directory is ${CATCH_BUILD_DIR}.\n" | ||
|
||
echo -e "Installing Debug configuration.\n" | ||
cmake -S $CATCH_BUILD_DIR/.. -B $CATCH_BUILD_DIR -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF "$@" | ||
cmake --build $CATCH_BUILD_DIR --config Debug --parallel | ||
cmake --install $CATCH_BUILD_DIR --config Debug | ||
|
||
echo -e "Installing RelWithDebInfo configuration.\n" | ||
cmake -S $CATCH_BUILD_DIR/.. -B $CATCH_BUILD_DIR -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=OFF "$@" | ||
cmake --build $CATCH_BUILD_DIR --config RelWithDebInfo --parallel | ||
cmake --install $CATCH_BUILD_DIR --config RelWithDebInfo | ||
|
||
echo -e "Installing Release configuration.\n" | ||
cmake -S $CATCH_BUILD_DIR/.. -B $CATCH_BUILD_DIR -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF "$@" | ||
cmake --build $CATCH_BUILD_DIR --config Release --parallel | ||
cmake --install $CATCH_BUILD_DIR --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RuleSet Name="Rules for GeneticAlgorithm" Description="Code analysis rules for GeneticAlgorithm.vcxproj." ToolsVersion="17.0"> | ||
<Include Path="cppcorecheckarithmeticrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckboundsrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckclassrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckconcurrencyrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckconstrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckdeclrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckenumrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckfuncrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckownerpointerrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckrawpointerrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorechecksharedpointerrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckstlrules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckstylerules.ruleset" Action="Default" /> | ||
<Include Path="cppcorechecktyperules.ruleset" Action="Default" /> | ||
<Include Path="cppcorecheckuniquepointerrules.ruleset" Action="Default" /> | ||
<Rules AnalyzerId="Microsoft.Analyzers.NativeCodeAnalysis" RuleNamespace="Microsoft.Rules.Native"> | ||
<!-- Disable rules that recommend using non-std functions. --> | ||
<Rule Id="C26429" Action="None" /> <!-- Use gsl::not_null<T>. --> | ||
<Rule Id="C26472" Action="None" /> <!-- Don't use a static_cast for arithmetic conversions. --> | ||
<Rule Id="C26446" Action="None" /> <!-- Prefer to use gsl::at() instead of unchecked subscript operator. --> | ||
|
||
<!-- Disable rules that are too noisy/not helpful. --> | ||
<Rule Id="C26493" Action="None" /> <!-- Don't use C-style casts. --> | ||
<Rule Id="C26496" Action="None" /> <!-- The variable 'xyz' is assigned only once, mark it as const. --> | ||
<Rule Id="C26814" Action="None" /> <!-- The const variable 'xyz' can be computed at compile time. Use constexpr. --> | ||
<Rule Id="C26812" Action="None" /> <!-- Prefer 'enum class' over 'enum'. --> | ||
<Rule Id="C26455" Action="None" /> <!-- Default constructor should not throw. Declare it 'noexcept'. --> | ||
|
||
<!-- Enable useful rules that are off by default. --> | ||
<Rule Id="C26815" Action="Warning" /> <!-- The pointer is dangling because it points at a temporary instance that was destroyed. --> | ||
<Rule Id="C26822" Action="Warning" /> <!-- Dereferencing a null pointer. --> | ||
</Rules> | ||
</RuleSet> |
Oops, something went wrong.