boostorg / boostorg/type_traits

Warnings after applying nodiscard to operators

Open
#139 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
66
Forks
87
PR merge metrics
No merged PRs in 30d

Description

I encountered this in Boost 1.68; I have not verified it in current Boost but I did manually inspect the relevant code and it appears to be unchanged, so I suspect the issue is still present.

If you apply the `[[nodiscard]]` attribute to various operators (such as `operator==` and `operator+`) -- as seems sensible as these are pure functions -- then VS2017 at least produces a warning that the return value is discarded:

```
t:\boost\boost_1_68_0\include\boost\type_traits\detail\has_binary_operator.hpp(149): warning C4834: discarding return value of function with 'nodiscard' attribute
t:\boost\boost_1_68_0\include\boost\type_traits\detail\has_binary_operator.hpp(233): note: see reference to class template instantiation 'boost::detail::has_equal_to_impl::operator_returns_void' being compiled
```

(In my case this originated from a call to `boost::has_equal_to` and `boost::has_less` (and thus `operator==` and `operator<`), but it would presumably affect any other binary operator, and most likely other operator types as well.)

Most likely this just needs an explicit cast to `void` to silence the warning.

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect boost/type_traits/detail/has_binary_operator.hpp around lines 149 and 233, starting with the operator-return checks that trigger C4834 under VS2017. Confirm whether the warning remains in a current Boost checkout and identify the affected operator cases. Done means the relevant nodiscard operator checks compile without discarded-return warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.