leaf icon indicating copy to clipboard operation
leaf copied to clipboard

Should leaf::result be [[nodiscard]]?

Open Snarpix opened this issue 2 years ago • 4 comments

There is no good use case to silently ignore error...

Snarpix avatar Sep 22 '23 11:09 Snarpix

Indeed. LEAF is (mostly) C++11, it's why this was omitted initially, but you're right, if C++17 is available, [[nodiscard]] should be used. Fixed.

zajo avatar Sep 22 '23 23:09 zajo

Hi, it looks like this commit https://github.com/boostorg/leaf/commit/971ecacf0fb753bf51f892589249df315b7522c6 removed the [[nodiscard]] attribute.

The commit in question entered in 1.85, it was working in 1.84.

The class declaration changed from class BOOST_LEAF_NODISCARD result to class BOOST_LEAF_SYMBOL_VISIBLE result.

This can be checked with the following example:

#include "boost/leaf.hpp"

// uncomment nodiscard attribute to trigger warninng
/*[[nodiscard]]*/ boost::leaf::result<void> func() {
  return {};
}

int main()
{
  func();
  return 0;
}

indiosmo avatar May 08 '24 20:05 indiosmo

Changing the lines below seems to do the trick but I'm not familiar with the codebase to know if this can have negative repercusions. Let me know if you'd like me to do a pull request.

177: class BOOST_LEAF_SYMBOL_VISIBLE BOOST_LEAF_ATTRIBUTE_NODISCARD result 623 class BOOST_LEAF_SYMBOL_VISIBLE BOOST_LEAF_ATTRIBUTE_NODISCARD result<void>:

indiosmo avatar May 08 '24 20:05 indiosmo

Woops. Thanks, yes a PR would be appreciated, that way it'll trigger the tests too.

zajo avatar May 09 '24 00:05 zajo