Skip to content

Commit fe3dbca

Browse files
committed
Added noexcept to a few places diagnosed by -Wnoexcept.
1 parent 6cceb01 commit fe3dbca

File tree

5 files changed

+79
-28
lines changed

5 files changed

+79
-28
lines changed

include/mpark/lib.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ namespace mpark {
302302
// <memory>
303303
#ifdef MPARK_BUILTIN_ADDRESSOF
304304
template <typename T>
305-
inline constexpr T *addressof(T &arg) {
305+
inline constexpr T *addressof(T &arg) noexcept {
306306
return __builtin_addressof(arg);
307307
}
308308
#else
@@ -327,19 +327,19 @@ namespace mpark {
327327
using has_addressof = bool_constant<has_addressof_impl::impl<T>()>;
328328

329329
template <typename T>
330-
inline constexpr T *addressof(T &arg, std::true_type) {
330+
inline constexpr T *addressof(T &arg, std::true_type) noexcept {
331331
return std::addressof(arg);
332332
}
333333

334334
template <typename T>
335-
inline constexpr T *addressof(T &arg, std::false_type) {
335+
inline constexpr T *addressof(T &arg, std::false_type) noexcept {
336336
return &arg;
337337
}
338338

339339
} // namespace detail
340340

341341
template <typename T>
342-
inline constexpr T *addressof(T &arg) {
342+
inline constexpr T *addressof(T &arg) noexcept {
343343
return detail::addressof(arg, detail::has_addressof<T>{});
344344
}
345345
#endif

include/mpark/variant.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,13 @@ namespace mpark {
491491

492492
struct base {
493493
template <typename T>
494-
inline static constexpr const T &at(const T &elem) {
494+
inline static constexpr const T &at(const T &elem) noexcept {
495495
return elem;
496496
}
497497

498498
template <typename T, std::size_t N, typename... Is>
499499
inline static constexpr const lib::remove_all_extents_t<T> &at(
500-
const lib::array<T, N> &elems, std::size_t i, Is... is) {
500+
const lib::array<T, N> &elems, std::size_t i, Is... is) noexcept {
501501
return at(elems[i], is...);
502502
}
503503

@@ -1520,7 +1520,7 @@ namespace mpark {
15201520
namespace detail {
15211521
template <std::size_t I, typename V>
15221522
struct generic_get_impl {
1523-
constexpr generic_get_impl(int) {}
1523+
constexpr generic_get_impl(int) noexcept {}
15241524

15251525
constexpr AUTO_REFREF operator()(V &&v) const
15261526
AUTO_REFREF_RETURN(
@@ -1814,14 +1814,14 @@ namespace mpark {
18141814
namespace hash {
18151815

18161816
template <typename H, typename K>
1817-
constexpr bool meets_requirements() {
1817+
constexpr bool meets_requirements() noexcept {
18181818
return std::is_copy_constructible<H>::value &&
18191819
std::is_move_constructible<H>::value &&
18201820
lib::is_invocable_r<std::size_t, H, const K &>::value;
18211821
}
18221822

18231823
template <typename K>
1824-
constexpr bool is_enabled() {
1824+
constexpr bool is_enabled() noexcept {
18251825
using H = std::hash<K>;
18261826
return meets_requirements<H, K>() &&
18271827
std::is_default_constructible<H>::value &&

test/intro.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ TEST(Variant, Intro) {
3535
v = 42;
3636

3737
struct unary {
38-
int operator()(int) const { return 0; }
39-
int operator()(const std::string &) const { return 1; }
38+
int operator()(int) const noexcept { return 0; }
39+
int operator()(const std::string &) const noexcept { return 1; }
4040
}; // unary
4141

4242
// single visitation.
@@ -53,10 +53,12 @@ TEST(Variant, Intro) {
5353
EXPECT_EQ(v, w);
5454

5555
struct binary {
56-
int operator()(int, int) const { return 0; }
57-
int operator()(int, const std::string &) const { return 1; }
58-
int operator()(const std::string &, int) const { return 2; }
59-
int operator()(const std::string &, const std::string &) const { return 3; }
56+
int operator()(int, int) const noexcept { return 0; }
57+
int operator()(int, const std::string &) const noexcept { return 1; }
58+
int operator()(const std::string &, int) const noexcept { return 2; }
59+
int operator()(const std::string &, const std::string &) const noexcept {
60+
return 3;
61+
}
6062
}; // binary
6163

6264
// binary visitation.

test/swap.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ struct Obj {
119119
size_t *dtor_count_;
120120
}; // Obj
121121

122-
static void swap(Obj &lhs, Obj &rhs) { std::swap(lhs.dtor_count_, rhs.dtor_count_); }
122+
static void swap(Obj &lhs, Obj &rhs) noexcept {
123+
std::swap(lhs.dtor_count_, rhs.dtor_count_);
124+
}
123125

124126
} // namespace detail
125127

test/util.hpp

+59-12
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,35 @@ struct copy_thrower_t {
3636
copy_thrower_t &operator=(copy_thrower_t &&) = default;
3737
};
3838

39-
bool operator<(const copy_thrower_t &, const copy_thrower_t &) { return false; }
40-
bool operator>(const copy_thrower_t &, const copy_thrower_t &) { return false; }
41-
bool operator<=(const copy_thrower_t &, const copy_thrower_t &) { return true; }
42-
bool operator>=(const copy_thrower_t &, const copy_thrower_t &) { return true; }
43-
bool operator==(const copy_thrower_t &, const copy_thrower_t &) { return true; }
44-
bool operator!=(const copy_thrower_t &, const copy_thrower_t &) { return false; }
39+
inline bool operator<(const copy_thrower_t &,
40+
const copy_thrower_t &) noexcept {
41+
return false;
42+
}
43+
44+
inline bool operator>(const copy_thrower_t &,
45+
const copy_thrower_t &) noexcept {
46+
return false;
47+
}
48+
49+
inline bool operator<=(const copy_thrower_t &,
50+
const copy_thrower_t &) noexcept {
51+
return true;
52+
}
53+
54+
inline bool operator>=(const copy_thrower_t &,
55+
const copy_thrower_t &) noexcept {
56+
return true;
57+
}
58+
59+
inline bool operator==(const copy_thrower_t &,
60+
const copy_thrower_t &) noexcept {
61+
return true;
62+
}
63+
64+
inline bool operator!=(const copy_thrower_t &,
65+
const copy_thrower_t &) noexcept {
66+
return false;
67+
}
4568

4669
struct move_thrower_t {
4770
constexpr move_thrower_t() {}
@@ -51,10 +74,34 @@ struct move_thrower_t {
5174
move_thrower_t &operator=(move_thrower_t &&) { throw MoveAssignment{}; }
5275
};
5376

54-
bool operator<(const move_thrower_t &, const move_thrower_t &) { return false; }
55-
bool operator>(const move_thrower_t &, const move_thrower_t &) { return false; }
56-
bool operator<=(const move_thrower_t &, const move_thrower_t &) { return true; }
57-
bool operator>=(const move_thrower_t &, const move_thrower_t &) { return true; }
58-
bool operator==(const move_thrower_t &, const move_thrower_t &) { return true; }
59-
bool operator!=(const move_thrower_t &, const move_thrower_t &) { return false; }
77+
inline bool operator<(const move_thrower_t &,
78+
const move_thrower_t &) noexcept {
79+
return false;
80+
}
81+
82+
inline bool operator>(const move_thrower_t &,
83+
const move_thrower_t &) noexcept {
84+
return false;
85+
}
86+
87+
inline bool operator<=(const move_thrower_t &,
88+
const move_thrower_t &) noexcept {
89+
return true;
90+
}
91+
92+
inline bool operator>=(const move_thrower_t &,
93+
const move_thrower_t &) noexcept {
94+
return true;
95+
}
96+
97+
inline bool operator==(const move_thrower_t &,
98+
const move_thrower_t &) noexcept {
99+
return true;
100+
}
101+
102+
inline bool operator!=(const move_thrower_t &,
103+
const move_thrower_t &) noexcept {
104+
return false;
105+
}
106+
60107
#endif

0 commit comments

Comments
 (0)