Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 58ad2a1

Browse files
authored
Merge pull request #14 from dermojo/extend-ci
Extend ci
2 parents fc14a15 + 89faa57 commit 58ad2a1

File tree

13 files changed

+175
-93
lines changed

13 files changed

+175
-93
lines changed

.clang-tidy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
# enable useful checks and disable a bunch of false positives :-(
3+
# TODO: splitting into multiple lines doesn't seem to work...
4+
Checks: 'clan*,cert*,misc*,perf*,cppc*,mode*,-*pointer-arithmetic,-*vararg,-*reinterpret-cast,-*array-to-pointer-decay,-*union-access,-cppcoreguidelines-pro-type-member-init,-cert-dcl50-cpp,-cppcoreguidelines-c-copy-assignment-signature,-misc-unconventional-assign-operator,-cppcoreguidelines-no-malloc,-cppcoreguidelines-pro-bounds-constant-array-index,-cert-err60-cpp'
5+
6+
WarningsAsErrors: ''
7+
HeaderFilterRegex: '.*'
8+
AnalyzeTemporaryDtors: false
9+
User: daniel
10+
CheckOptions:
11+
- key: modernize-loop-convert.MaxCopySize
12+
value: '16'
13+
- key: modernize-loop-convert.MinConfidence
14+
value: reasonable
15+
- key: modernize-loop-convert.NamingStyle
16+
value: CamelCase
17+
- key: modernize-pass-by-value.IncludeStyle
18+
value: llvm
19+
- key: modernize-replace-auto-ptr.IncludeStyle
20+
value: llvm
21+
- key: modernize-use-nullptr.NullMacros
22+
value: 'NULL'
23+
...
24+

.travis.yml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,74 @@ matrix:
4646
packages:
4747
- clang-3.9
4848
env: MYCC=clang-3.9 MYCXX=clang++-3.9
49+
- compiler: clang
50+
addons:
51+
apt:
52+
sources:
53+
- ubuntu-toolchain-r-test
54+
- llvm-toolchain-trusty-4.0
55+
packages:
56+
- clang-4.0
57+
env: MYCC=clang-4.0 MYCXX=clang++-4.0
58+
- os: linux
59+
env:
60+
- TEST="Clang Format"
61+
addons:
62+
apt:
63+
sources:
64+
- ubuntu-toolchain-r-test
65+
- llvm-toolchain-trusty
66+
packages:
67+
- clang-format
68+
script:
69+
- mkdir build
70+
- cd build
71+
- cmake ..
72+
- make format
73+
- |
74+
if [[ -n $(git diff) ]]; then
75+
echo "You must run make format before submitting a pull request"
76+
echo ""
77+
git diff
78+
exit -1
79+
fi
80+
- os: linux
81+
env:
82+
- TEST="Clang Tidy"
83+
addons:
84+
apt:
85+
sources:
86+
- ubuntu-toolchain-r-test
87+
- llvm-toolchain-trusty-4.0
88+
packages:
89+
- clang-tidy-4.0
90+
- clang-4.0
91+
script:
92+
- mkdir build
93+
- cd build
94+
- cmake .. -DCMAKE_C_COMPILER=clang-4.0 -DCMAKE_CXX_COMPILER=clang++-4.0
95+
- make tidy >output.txt
96+
- |
97+
if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then
98+
echo "You must pass the clang tidy checks before submitting a pull request"
99+
echo ""
100+
grep --color -E '^|warning: |error: ' output.txt
101+
exit -1;
102+
else
103+
echo -e "\033[1;32m\xE2\x9C\x93 passed:\033[0m $1";
104+
fi
49105
50106
before_install:
51107
- sudo apt-get install -y libgtest-dev
52108

53-
script:
109+
before_script:
54110
- cd /usr/src/gtest
55111
- sudo cmake -DCMAKE_C_COMPILER=$MYCC -DCMAKE_CXX_COMPILER=$MYCXX .
56112
- sudo cmake --build .
57113
- sudo mv libg* /usr/local/lib/
58114
- cd $TRAVIS_BUILD_DIR
115+
116+
script:
59117
- mkdir build
60118
- cd build
61119
- cmake -DCMAKE_C_COMPILER=$MYCC -DCMAKE_CXX_COMPILER=$MYCXX ..

CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,43 @@ endif()
7676
# use this to enable C++17 tests (esp. string_view) with GCC/Clang
7777
# (but comment the CXX_STANDARD* settings above)
7878
#target_compile_options(testlib PUBLIC -std=c++1z)
79+
80+
# run clang-format on all files
81+
list(APPEND CLANG_FORMAT_ARGS
82+
-style=file
83+
-i
84+
${CMAKE_SOURCE_DIR}/include/*.hpp
85+
${CMAKE_SOURCE_DIR}/include/spsl/*.hpp
86+
${CMAKE_SOURCE_DIR}/test/*.hpp
87+
${CMAKE_SOURCE_DIR}/test/*.cpp
88+
)
89+
90+
if(NOT WIN32 STREQUAL "1")
91+
add_custom_target(
92+
format
93+
COMMAND clang-format ${CLANG_FORMAT_ARGS}
94+
COMMENT "running clang-format"
95+
)
96+
else()
97+
add_custom_target(
98+
format
99+
COMMAND clang-format.exe ${CLANG_FORMAT_ARGS}
100+
COMMENT "running clang-format"
101+
)
102+
endif()
103+
104+
# clang tidy support (using version 4.0 atm)
105+
# (since this is a header-only library, it's sufficient to check a single source that includes
106+
# everything)
107+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
108+
set(CLANG_TIDY /usr/bin/clang-tidy-4.0)
109+
list(APPEND CLANG_TIDY_ARGS
110+
-p .
111+
${CMAKE_SOURCE_DIR}/test/example.cpp
112+
)
113+
114+
add_custom_target(
115+
tidy
116+
COMMAND ${CLANG_TIDY} ${CLANG_TIDY_ARGS}
117+
COMMENT "running clang tidy"
118+
)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ The SPSL itself only relies on the STL and has no dependencies. To compile the t
3838
* [CMake](https://cmake.org/) 3.2 or higher
3939
* [GoogleTest](https://github.com/google/googletest) 1.8
4040

41-
Supported compilers (we'll, the ones I've tested) include GCC 4.9/5/6 and clang 3.8/3.9 on Linux,
42-
Microsoft Visual Studio 2013 (Update 5) and Microsoft Visual Studio 2015.
41+
Supported compilers (we'll, the ones I've tested) include GCC 4.9/5/6 and clang 3.8/3.9/4.0
42+
on Linux, Microsoft Visual Studio 2013 (Update 5) and Microsoft Visual Studio 2015.
4343

4444

4545
## Running the tests
4646

4747
SPSL comes with a lot of unit tests. They are compiled into the `testlib` executable, which can
48-
be run standalone or from cmake/ctest.
48+
be run standalone or from cmake/ctest.
4949

5050
To build on Linux, simply run CMake and execute the tests:
5151
mkdir build
@@ -75,4 +75,4 @@ tl;dr: Feel free to use and modify the code or to include it in your commercial
7575
## Acknowledgements
7676

7777
This library uses the MurmurHash3 hash functions, copied thankfully from
78-
[https://github.com/aappleby/smhasher](https://github.com/aappleby/smhasher). Thanks a lot!
78+
[https://github.com/aappleby/smhasher](https://github.com/aappleby/smhasher). Thanks a lot!

include/spsl/compat.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <system_error>
1212

1313
#define SPSL_HAS_NOEXCEPT
14-
#define SPSL_HAS_DEFAULT_MOVE
1514
#define SPSL_HAS_CONSTEXPR_ARRAY
1615

1716
#ifdef _WIN32 // Windows
@@ -26,7 +25,6 @@ typedef intptr_t ssize_t;
2625
#define noexcept
2726
#define constexpr const
2827
#undef SPSL_HAS_NOEXCEPT
29-
#undef SPSL_HAS_DEFAULT_MOVE
3028
#endif
3129

3230
// can't use constexpr values in array definitions...

include/spsl/hash.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ FORCE_INLINE uint64_t fmix64(uint64_t k)
117117

118118
inline void MurmurHash3_x86_32(const void* key, const uint32_t len, uint32_t seed, void* out)
119119
{
120-
const uint8_t* data = reinterpret_cast<const uint8_t*>(key);
120+
auto data = reinterpret_cast<const uint8_t*>(key);
121121
const uint32_t nblocks = len / 4;
122122

123123
uint32_t h1 = seed;
@@ -128,7 +128,7 @@ inline void MurmurHash3_x86_32(const void* key, const uint32_t len, uint32_t see
128128
//----------
129129
// body
130130

131-
const uint32_t* blocks = reinterpret_cast<const uint32_t*>(data);
131+
auto blocks = reinterpret_cast<const uint32_t*>(data);
132132

133133
for (uint32_t i = 0; i < nblocks; ++i)
134134
{
@@ -181,7 +181,7 @@ inline void MurmurHash3_x86_32(const void* key, const uint32_t len, uint32_t see
181181
inline void MurmurHash3_x64_128(const void* key, const std::size_t len, const uint32_t seed,
182182
void* out)
183183
{
184-
const uint8_t* data = reinterpret_cast<const uint8_t*>(key);
184+
auto data = reinterpret_cast<const uint8_t*>(key);
185185
const std::size_t nblocks = len / 16;
186186

187187
uint64_t h1 = seed;
@@ -193,7 +193,7 @@ inline void MurmurHash3_x64_128(const void* key, const std::size_t len, const ui
193193
//----------
194194
// body
195195

196-
const uint64_t* blocks = reinterpret_cast<const uint64_t*>(data);
196+
auto blocks = reinterpret_cast<const uint64_t*>(data);
197197

198198
for (std::size_t i = 0; i < nblocks; i++)
199199
{

include/spsl/pagealloc.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,14 @@ class SensitivePageAllocator
5757
{
5858
AllocationInfo(pointer a, std::size_t s) : addr(a), size(s) {}
5959
AllocationInfo(const AllocationInfo&) noexcept = default;
60-
#ifdef SPSL_HAS_DEFAULT_MOVE
61-
AllocationInfo(AllocationInfo&&) noexcept = default;
62-
#else
6360
AllocationInfo(AllocationInfo&& other) noexcept : addr(other.addr), size(other.size) {}
64-
#endif
6561
AllocationInfo& operator=(const AllocationInfo&) noexcept = default;
66-
#ifdef SPSL_HAS_DEFAULT_MOVE
67-
AllocationInfo& operator=(AllocationInfo&&) noexcept = default;
68-
#else
6962
AllocationInfo& operator=(AllocationInfo&& other) noexcept
7063
{
7164
addr = other.addr;
7265
size = other.size;
7366
return *this;
7467
}
75-
#endif
7668
~AllocationInfo() = default;
7769

7870
/// the allocated address
@@ -195,6 +187,11 @@ class SensitivePageAllocator
195187
}
196188
}
197189

190+
// disable copy & move
191+
SensitivePageAllocator(const SensitivePageAllocator&) = delete;
192+
SensitivePageAllocator(SensitivePageAllocator&&) = delete;
193+
SensitivePageAllocator& operator=(const SensitivePageAllocator&) = delete;
194+
SensitivePageAllocator& operator=(SensitivePageAllocator&&) = delete;
198195

199196
/**
200197
* Returns the "default instance", a.k.a. a static instance of the allocator. The instance is

include/spsl/storage_array.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ class StorageArray
307307
*this = std::move(tmp);
308308
}
309309

310-
void swap(this_type& other) { std::swap(*this, other); }
310+
void swap(this_type& other) noexcept
311+
{
312+
std::swap(m_length, other.m_length);
313+
std::swap(m_buffer, other.m_buffer);
314+
}
311315

312316
protected:
313317
void assign_nothrow(const char_type* s, size_type len) noexcept
@@ -319,7 +323,7 @@ class StorageArray
319323

320324
protected:
321325
/// number of bytes (*not* characters) in the buffer, not including the terminating NUL
322-
size_type m_length;
326+
size_type m_length; // NOLINT: disable modernize-use-default-member-init
323327
/// the underlying buffer: an array that can hold MaxSize characters (+ terminating NUL)
324328
std::array<char_type, MaxSize + 1> m_buffer;
325329
};

include/spsl/stringbase.hpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ class StringBase : public StringCore<StorageType>
101101
// default destructor, move and copy
102102
~StringBase() = default;
103103
StringBase(const this_type&) = default;
104-
#ifdef SPSL_HAS_DEFAULT_MOVE
105-
StringBase(this_type&&) = default;
106-
#else
107-
StringBase(this_type&& rhs) { this->swap(rhs); }
108-
#endif
104+
StringBase(this_type&& rhs) noexcept : StringBase() { this->swap(rhs); }
109105

110106
/// construct from another storage instance
111107
explicit StringBase(const storage_type& storage) : base_type(storage) {}
@@ -138,15 +134,11 @@ class StringBase : public StringCore<StorageType>
138134

139135
// default copy & move
140136
this_type& operator=(const this_type&) = default;
141-
#ifdef SPSL_HAS_DEFAULT_MOVE
142-
this_type& operator=(this_type&&) = default;
143-
#else
144-
this_type& operator=(this_type&& rhs)
137+
this_type& operator=(this_type&& rhs) noexcept
145138
{
146139
this->swap(rhs);
147140
return *this;
148141
}
149-
#endif
150142

151143
/// allow assignment from another string-like container (may even be a vector...)
152144
template <typename StringClass, typename std::enable_if<is_compatible_string<
@@ -295,8 +287,8 @@ class StringBase : public StringCore<StorageType>
295287
template <class InputIt, typename = checkInputIter<InputIt>>
296288
this_type& replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2)
297289
{
298-
size_type pos = static_cast<size_type>(first - data());
299-
size_type count = static_cast<size_type>(last - first);
290+
auto pos = static_cast<size_type>(first - data());
291+
auto count = static_cast<size_type>(last - first);
300292
if (pos > size())
301293
throw std::out_of_range("replace: pos > size()");
302294
if (pos + count > size())
@@ -556,17 +548,9 @@ struct hash<spsl::StringBase<StorageType>>
556548

557549
hash() = default;
558550
hash(const hash&) = default;
559-
#ifdef SPSL_HAS_DEFAULT_MOVE
560-
hash(hash&&) = default;
561-
#else
562-
hash(hash&&) {}
563-
#endif
551+
hash(hash&&) noexcept {}
564552
hash& operator=(const hash&) = default;
565-
#ifdef SPSL_HAS_DEFAULT_MOVE
566-
hash& operator=(hash&&) = default;
567-
#else
568-
hash& operator=(hash&&) { return *this; }
569-
#endif
553+
hash& operator=(hash&&) noexcept { return *this; }
570554
~hash() = default;
571555

572556
size_t operator()(const argument_type& s) const

0 commit comments

Comments
 (0)