Skip to content

Commit ea7af24

Browse files
committed
refactor: fixes clang compiler warnings
1 parent 315662a commit ea7af24

24 files changed

+773
-698
lines changed

.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inkcpp_compiler/json.hpp

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ repos:
44
hooks:
55
- id: clang-format
66
types_or: [c++, c, cuda]
7+
exclude: inkcpp_compiler/json.hpp
78

89
- repo: https://github.com/pre-commit/pre-commit-hooks
910
rev: v6.0.0

inkcpp/avl_array.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ class avl_array
112112
return *this;
113113
}
114114

115+
tag_avl_array_iterator(const tag_avl_array_iterator& other)
116+
: instance_{other.instance_}
117+
, idx_{other.idx_}
118+
{
119+
}
120+
115121
inline bool operator==(const tag_avl_array_iterator& rhs) const { return idx_ == rhs.idx_; }
116122

117123
inline bool operator!=(const tag_avl_array_iterator& rhs) const { return ! (*this == rhs); }

inkcpp/collections/restorable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ unsigned char*
1616
ptr = snapshot_interface::snap_write(ptr, jump, write);
1717
ptr = snapshot_interface::snap_write(ptr, save, write);
1818
max = pos;
19-
if (jump != ~0 && jump > max) {
19+
if (jump != ~0U && jump > max) {
2020
max = jump;
2121
}
22-
if (save != ~0 && save > max) {
22+
if (save != ~0U && save > max) {
2323
max = save;
2424
}
2525
return ptr;
@@ -32,10 +32,10 @@ const unsigned char*
3232
ptr = snapshot_interface::snap_read(ptr, jump);
3333
ptr = snapshot_interface::snap_read(ptr, save);
3434
max = pos;
35-
if (jump != ~0 && jump > max) {
35+
if (jump != ~0U && jump > max) {
3636
max = jump;
3737
}
38-
if (save != ~0 && save > max) {
38+
if (save != ~0U && save > max) {
3939
max = save;
4040
}
4141
return ptr;

inkcpp/collections/restorable.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
#pragma once
88

9-
#include "../snapshot_impl.h"
9+
#include "../snapshot_interface.h"
1010

1111
#include <system.h>
1212
#include <traits.h>
@@ -102,15 +102,15 @@ class restorable : public snapshot_interface
102102
}
103103

104104
// Checks if we have a save state
105-
bool is_saved() const { return _save != ~0; }
105+
bool is_saved() const { return _save != ~0U; }
106106

107107
// Creates a save point which can later be restored to or forgotten
108108
void save()
109109
{
110110
inkAssert(
111-
_save == ~0, "Collection is already saved. You should never call save twice. Ignoring."
111+
_save == ~0U, "Collection is already saved. You should never call save twice. Ignoring."
112112
);
113-
if (_save != ~0) {
113+
if (_save != ~0U) {
114114
return;
115115
}
116116

@@ -121,8 +121,8 @@ class restorable : public snapshot_interface
121121
// Restore to the last save point
122122
void restore()
123123
{
124-
inkAssert(_save != ~0, "Collection can't be restored because it's not saved. Ignoring.");
125-
if (_save == ~0) {
124+
inkAssert(_save != ~0U, "Collection can't be restored because it's not saved. Ignoring.");
125+
if (_save == ~0U) {
126126
return;
127127
}
128128

@@ -137,8 +137,8 @@ class restorable : public snapshot_interface
137137
template<typename NullifyMethod>
138138
void forget(NullifyMethod nullify)
139139
{
140-
inkAssert(_save != ~0, "Can't forget save point because there is none. Ignoring.");
141-
if (_save == ~0) {
140+
inkAssert(_save != ~0U, "Can't forget save point because there is none. Ignoring.");
141+
if (_save == ~0U) {
142142
return;
143143
}
144144

@@ -170,7 +170,7 @@ class restorable : public snapshot_interface
170170
ElementType& push(const ElementType& elem)
171171
{
172172
// Don't destroy saved data. Jump over it
173-
if (_pos < _save && _save != ~0) {
173+
if (_pos < _save && _save != ~0U) {
174174
_jump = _pos;
175175
_pos = _save;
176176
}
@@ -279,7 +279,7 @@ class restorable : public snapshot_interface
279279
void for_each_all(CallbackMethod callback) const
280280
{
281281
// no matter if we're saved or not, we iterate everything
282-
int len = (_save == ~0 || _pos > _save) ? _pos : _save;
282+
int len = (_save == ~0U || _pos > _save) ? _pos : _save;
283283

284284
// Iterate
285285
for (int i = 0; i < len; i++)
@@ -358,10 +358,7 @@ class restorable : public snapshot_interface
358358

359359
protected:
360360
// Called when we run out of space in buffer.
361-
virtual void overflow(ElementType*&, size_t&)
362-
{
363-
inkFail("Restorable run out of memory!");
364-
}
361+
virtual void overflow(ElementType*&, size_t&) { inkFail("Restorable run out of memory!"); }
365362

366363
private:
367364
template<typename Predicate>

inkcpp/include/choice.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ namespace runtime
8080
uint32_t _path = ~0U; ///< @private
8181
thread_t _thread = ~0U; ///< @private
8282
int _index = -1; ///< @private
83-
#pragma warning(push)
84-
#pragma warning(disable : 4820, justification : "4 byte aligment free on 64-bit systems")
8583
};
8684

87-
#pragma warning(pop)
8885
} // namespace runtime
8986
} // namespace ink

inkcpp/include/list.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class list_interface
4949
}
5050

5151
virtual list_interface& operator=(const list_interface&) = default;
52+
5253
virtual ~list_interface() {}
5354

5455
/** iterater for flags in a list
@@ -61,8 +62,6 @@ class list_interface
6162
const list_interface& _list;
6263
int _i;
6364
bool _one_list_iterator; ///< iterates only though values of one list
64-
#pragma warning(push)
65-
#pragma warning(disable : 4820, justification : "3 byte aligment free on 64-bit systems")
6665
friend list_interface;
6766
#ifdef INK_BUILD_CLIB
6867
friend int ::ink_list_flags(const HInkList*, InkListIter*);
@@ -123,10 +122,15 @@ class list_interface
123122
};
124123

125124

126-
#pragma warning(push)
127-
#pragma warning( \
128-
disable : 4100, justification : "non functional prototypes do not need the argument." \
129-
)
125+
#ifdef __GNUC__
126+
# pragma GCC diagnostic push
127+
# pragma GCC diagnostic ignored "-Wunused-parameter"
128+
#else
129+
# pragma warning(push)
130+
# pragma warning( \
131+
disable : 4100, justification : "non functional prototypes do not need the argument." \
132+
)
133+
#endif
130134

131135
/** checks if a flag is contained in the list */
132136
virtual bool contains(const char* flag) const
@@ -177,7 +181,11 @@ class list_interface
177181
inkAssert(false, "Not implemented funciton from interface is called!");
178182
};
179183

180-
#pragma warning(pop)
184+
#ifdef __GNUC__
185+
# pragma GCC diagnostic pop
186+
#else
187+
# pragma warning(pop)
188+
#endif
181189

182190
protected:
183191
/** @private */
@@ -199,5 +207,3 @@ class list_interface
199207
};
200208

201209
} // namespace ink::runtime
202-
203-
#pragma warning(pop)

inkcpp/include/story_ptr.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ namespace internal
1919
, valid(true)
2020
{
2121
}
22+
2223
static void remove_reference(ref_block*&);
2324

2425
size_t references;
2526
bool valid;
26-
#pragma warning(push)
27-
#pragma warning(disable : 4820, justification : "3 byte aligment free on 64-bit systems")
2827
};
2928

30-
#pragma warning(pop)
31-
3229
/** @private */
3330
class story_ptr_base
3431
{

inkcpp/include/types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ struct value {
5454
Float, ///< containing a float
5555
List ///< containing a @ref list_interface
5656
} type; ///< Label of type currently contained in @ref value
57-
#pragma warning(push)
58-
#pragma warning(disable : 4820, justification : "4 byte aligment free on 64-bit systems")
5957

6058
value()
6159
: v_int32{0}
@@ -128,8 +126,6 @@ struct value {
128126
}
129127
};
130128

131-
#pragma warning(pop)
132-
133129
/** access #value::Type::Bool value */
134130
template<>
135131
inline const auto& value::get<value::Type::Bool>() const

inkcpp/runner_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ink::runtime::internal
4242

4343
hash_t runner_impl::get_current_knot() const
4444
{
45-
return _current_knot_id == ~0 ? 0 : _story->container_hash(_current_knot_id);
45+
return _current_knot_id == ~0U ? 0 : _story->container_hash(_current_knot_id);
4646
}
4747

4848
template<>
@@ -599,7 +599,7 @@ void runner_impl::choose(size_t index)
599599

600600
// Figure out where our previous pointer was for that thread
601601
ip_t prev = nullptr;
602-
if (choiceThread == ~0) {
602+
if (choiceThread == ~0U) {
603603
prev = _done;
604604
} else {
605605
prev = _threads.get(choiceThread);
@@ -1543,7 +1543,7 @@ void runner_impl::on_done(bool setDone)
15431543
void runner_impl::set_done_ptr(ip_t ptr)
15441544
{
15451545
thread_t curr = current_thread();
1546-
if (curr == ~0) {
1546+
if (curr == ~0U) {
15471547
_done = ptr;
15481548
} else {
15491549
_threads.set(curr, ptr);

0 commit comments

Comments
 (0)