mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Mark finally with nodiscard attribute.
The compiler should warn about unsued result of finally(). See https://github.com/Microsoft/GSL/issues/284.
This commit is contained in:
parent
a9f865900d
commit
d947c740ee
@ -78,13 +78,20 @@ private:
|
|||||||
bool invoke_;
|
bool invoke_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// C++17 [[nodiscard]] attribute for legacy compilers.
|
||||||
|
#if _MSC_VER
|
||||||
|
#define GSL_NODISCARD _Check_return_
|
||||||
|
#else
|
||||||
|
#define GSL_NODISCARD __attribute__((warn_unused_result))
|
||||||
|
#endif
|
||||||
|
|
||||||
// finally() - convenience function to generate a final_act
|
// finally() - convenience function to generate a final_act
|
||||||
template <class F>
|
template <class F>
|
||||||
inline final_act<F> finally(const F &f)
|
GSL_NODISCARD inline final_act<F> finally(const F &f)
|
||||||
noexcept { return final_act<F>(f); }
|
noexcept { return final_act<F>(f); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
inline final_act<F> finally(F &&f) noexcept
|
GSL_NODISCARD inline final_act<F> finally(F &&f) noexcept
|
||||||
{ return final_act<F>(std::forward<F>(f)); }
|
{ return final_act<F>(std::forward<F>(f)); }
|
||||||
|
|
||||||
// narrow_cast(): a searchable way to do narrowing casts of values
|
// narrow_cast(): a searchable way to do narrowing casts of values
|
||||||
|
Loading…
Reference in New Issue
Block a user