boostorg / leaf

Lightweight Error Augmentation Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Snarpix opened this issue · comments

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

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.

Hi, it looks like this commit 971ecac 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;
}

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>:

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