Skip to content

Commit e0caad9

Browse files
committed
Fix compiler warnings
run-clang-tidy -fix -checks=bugprone-assert-side-effect,hicpp-*
1 parent afd9ff9 commit e0caad9

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

examples/fibonacci.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ template <int Capacity> inplace_vector<int, Capacity> fibonacci_to(int num) {
4242
*/
4343
int main() {
4444
auto fib_seq = fibonacci_to<50>(10);
45-
for (auto i = 0u; i < fib_seq.size(); ++i)
45+
for (auto i = 0U; i < fib_seq.size(); ++i) {
4646
std::cout << i << ": " << fib_seq[i] << "\n";
47+
}
4748
std::cout << std::endl;
4849
}

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
335335
for (; first != last; ++first) {
336336
emplace_back(*first);
337337
}
338-
}; // freestanding-deleted
338+
} // freestanding-deleted
339339

340340
#if defined(__cpp_lib_containers_ranges) and defined(__cpp_concepts)
341341
template <typename R>
@@ -359,7 +359,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
359359
for (; first != last; ++first) {
360360
emplace_back(*first);
361361
}
362-
}; // freestanding-deleted
362+
} // freestanding-deleted
363363
#endif
364364

365365
constexpr void assign(size_type n, const T &u) {
@@ -434,7 +434,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
434434

435435
constexpr reverse_iterator rbegin() noexcept {
436436
return reverse_iterator{this->end()};
437-
};
437+
}
438438
constexpr const_reverse_iterator rbegin() const noexcept {
439439
return const_reverse_iterator{this->end()};
440440
}
@@ -452,13 +452,13 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
452452

453453
constexpr const_reverse_iterator crend() const noexcept {
454454
return const_reverse_iterator{this->begin()};
455-
};
455+
}
456456

457457
// [containers.sequences.inplace.vector.members] size/capacity
458-
constexpr bool empty() const noexcept { return size() == 0; };
459-
constexpr size_type size() const noexcept { return this->size_; };
460-
static constexpr size_type max_size() noexcept { return Capacity; };
461-
static constexpr size_type capacity() noexcept { return Capacity; };
458+
constexpr bool empty() const noexcept { return size() == 0; }
459+
constexpr size_type size() const noexcept { return this->size_; }
460+
static constexpr size_type max_size() noexcept { return Capacity; }
461+
static constexpr size_type capacity() noexcept { return Capacity; }
462462
constexpr void resize(size_type sz) {
463463
const auto diff = static_cast<std::ptrdiff_t>(sz - this->size());
464464
if (diff < 0) {
@@ -471,7 +471,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
471471
base::uninitialized_value_construct(end, end + diff);
472472
}
473473
this->change_size(diff);
474-
}; // freestanding-deleted
474+
} // freestanding-deleted
475475
constexpr void resize(size_type sz, const T &c) {
476476
const auto diff = static_cast<std::ptrdiff_t>(sz - this->size());
477477
if (diff < 0) {
@@ -484,12 +484,12 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
484484
std::uninitialized_fill(end, end + diff, c);
485485
}
486486
this->change_size(diff);
487-
}; // freestanding-deleted
487+
} // freestanding-deleted
488488
static constexpr void reserve(size_type sz) {
489489
if (Capacity < sz) {
490490
throw std::bad_alloc();
491491
}
492-
}; // freestanding-deleted
492+
} // freestanding-deleted
493493
static constexpr void shrink_to_fit() noexcept {}
494494

495495
// [containers.sequences.inplace.vector.modifiers], modifiers
@@ -498,20 +498,20 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
498498
throw std::bad_alloc();
499499
}
500500
return this->unchecked_emplace_back(std::forward<Args>(args)...);
501-
}; // freestanding-deleted
501+
} // freestanding-deleted
502502

503503
constexpr reference push_back(const T &x) {
504504
if (this->size() == Capacity) {
505505
throw std::bad_alloc();
506506
}
507507
return this->unchecked_emplace_back(x);
508-
}; // freestanding-deleted
508+
} // freestanding-deleted
509509
constexpr reference push_back(T &&x) {
510510
if (this->size() == Capacity) {
511511
throw std::bad_alloc();
512512
}
513513
return this->unchecked_emplace_back(std::move(x));
514-
}; // freestanding-deleted
514+
} // freestanding-deleted
515515

516516
#if defined(__cpp_lib_containers_ranges) and defined(__cpp_concepts)
517517
template <typename R>
@@ -522,7 +522,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
522522
for (; first != last; ++first) {
523523
emplace_back(*first);
524524
}
525-
}; // freestanding-deleted
525+
} // freestanding-deleted
526526
#endif
527527

528528
constexpr void pop_back() {
@@ -531,30 +531,30 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
531531
std::destroy(end, end + 1);
532532
this->change_size(-1);
533533
}
534-
};
534+
}
535535

536536
template <class... Args> constexpr pointer try_emplace_back(Args &&...args) {
537537
if (this->size() == Capacity) {
538538
return nullptr;
539539
}
540540
return std::addressof(
541541
this->unchecked_emplace_back(std::forward<Args>(args)...));
542-
};
542+
}
543543
constexpr pointer
544544
try_push_back(const T &x) noexcept(std::is_nothrow_copy_constructible_v<T>) {
545545
if (this->size() == Capacity) {
546546
return nullptr;
547547
}
548548
return std::addressof(this->unchecked_emplace_back(x));
549-
};
549+
}
550550

551551
constexpr pointer
552552
try_push_back(T &&x) noexcept(std::is_nothrow_move_constructible_v<T>) {
553553
if (this->size() == Capacity) {
554554
return nullptr;
555555
}
556556
return std::addressof(this->unchecked_emplace_back(std::move(x)));
557-
};
557+
}
558558

559559
/*
560560
template <typename R>
@@ -566,7 +566,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
566566
emplace_back(*first);
567567
}
568568
return frist;
569-
};
569+
}
570570
*/
571571

572572
template <class... Args>
@@ -580,15 +580,15 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
580580
#endif
581581
this->change_size(1);
582582
return *final;
583-
};
583+
}
584584

585585
constexpr reference
586586
unchecked_push_back(const T &x) noexcept(std::is_nothrow_constructible_v<T>) {
587587
return this->unchecked_emplace_back(x);
588-
};
588+
}
589589
constexpr reference unchecked_push_back(T &&x) {
590590
return this->unchecked_emplace_back(std::move(x));
591-
};
591+
}
592592

593593
template <class... Args>
594594
constexpr iterator emplace(const_iterator position, Args &&...args) {
@@ -609,13 +609,13 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
609609
*pos = std::move(temp);
610610
}
611611
return pos;
612-
}; // freestanding-deleted
612+
} // freestanding-deleted
613613
constexpr iterator insert(const_iterator position, const T &x) {
614614
return emplace(position, x);
615-
}; // freestanding-deleted
615+
} // freestanding-deleted
616616
constexpr iterator insert(const_iterator position, T &&x) {
617617
return emplace(position, std::move(x));
618-
}; // freestanding-deleted
618+
} // freestanding-deleted
619619
constexpr iterator insert(const_iterator position, size_type n, const T &x) {
620620
const iterator pos = position;
621621
const iterator end = this->end();
@@ -781,7 +781,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
781781
constexpr friend std::compare_three_way_result<T>
782782
operator<=>(const inplace_vector &x, const inplace_vector &y) {
783783
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
784-
};
784+
}
785785
#endif
786786

787787
constexpr friend void swap(inplace_vector &x, inplace_vector &y) noexcept(

tests/beman/inplace_vector/inplace_vector.test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ template <typename T> constexpr void test() {
3131
static_assert(std::is_same<decltype(const_bracket),
3232
typename vec::const_reference>::value,
3333
"");
34-
assert(front = T(1));
34+
assert(front == T(1));
3535

3636
auto &&const_front = const_range.front();
3737
static_assert(
@@ -69,13 +69,15 @@ void test_exceptions() {
6969
try {
7070
vec too_small{};
7171
auto res = too_small.at(5);
72+
(void)res;
7273
} catch (const std::out_of_range &) {
7374
} catch (...) {
7475
assert(false);
7576
}
7677
try {
7778
const vec too_small{};
7879
auto res = too_small.at(5);
80+
(void)res;
7981
} catch (const std::out_of_range &) {
8082
} catch (...) {
8183
assert(false);

0 commit comments

Comments
 (0)