diff --git a/include/gsl_util.h b/include/gsl_util.h index edfcce4..430a57b 100644 --- a/include/gsl_util.h +++ b/include/gsl_util.h @@ -78,13 +78,20 @@ private: 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 template -inline final_act finally(const F &f) +GSL_NODISCARD inline final_act finally(const F &f) noexcept { return final_act(f); } template -inline final_act finally(F &&f) noexcept +GSL_NODISCARD inline final_act finally(F &&f) noexcept { return final_act(std::forward(f)); } // narrow_cast(): a searchable way to do narrowing casts of values