Skip to content

Commit

Permalink
remove gcc noexcept warning (#1122)
Browse files Browse the repository at this point in the history
Without this change a `gsl::not_null<class_type>` triggers these `noexcept` warnings:
```
.../gsl/include/gsl/pointers:162:50: warning: noexcept-expression evaluates to ‘false’ because of a call to ‘constexpr gsl::details::value_or_reference_return_t<T> gsl::not_null<T>::get() const [with T = class_type*; gsl::details::value_or_reference_return_t<T> = class_type* const]’ [-Wnoexcept]
  162 |                 const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get()))
      |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../gsl/include/gsl/pointers:119:55: note: but ‘constexpr gsl::details::value_or_reference_return_t<T> gsl::not_null<T>::get() const [with T = class_type*; gsl::details::value_or_reference_return_t<T> = class_type* const]’ does not throw; perhaps it should be declared ‘noexcept’
  119 |     constexpr details::value_or_reference_return_t<T> get() const
      |                                                       ^~~
```

Co-authored-by: Werner Henze <w.henze@avm.de>
  • Loading branch information
beinhaerter and Werner Henze authored Jun 28, 2023
1 parent 3549e31 commit 87e2140
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions include/gsl/pointers
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public:
not_null(const not_null& other) = default;
not_null& operator=(const not_null& other) = default;
constexpr details::value_or_reference_return_t<T> get() const
noexcept(noexcept(details::value_or_reference_return_t<T>{ptr_}))
{
return ptr_;
}
Expand Down

0 comments on commit 87e2140

Please sign in to comment.