24-08-2025, 03:23 PM
Regarding your specific questions:
1) There is no intention to encourage the use of operators over functions. Indeed, we'd regard the use of operators instead of
functions purely to avoid the requirements of this rule as a form of 'malicious compliance'
2) The fact that “it is possible to call a function without using the return value, which may be an error" is not a justification to
make the rule advisory.
The aim of the rule is to ensure that the programmer has not accidentally discarded the return value.
Where a function returns a value that intentionally isn't being used, then casting the return value to 'void' satisfies the
requirements of the rules and shows that the discard is intentional.
3) The concern is that all return values should be used, unless explicitly discarded. The concern is not restricted to error reports.
We've noted the point you make regarding 'push_back' and 'emplace_back' and will consider any changes that may be appropriate.
1) There is no intention to encourage the use of operators over functions. Indeed, we'd regard the use of operators instead of
functions purely to avoid the requirements of this rule as a form of 'malicious compliance'
2) The fact that “it is possible to call a function without using the return value, which may be an error" is not a justification to
make the rule advisory.
The aim of the rule is to ensure that the programmer has not accidentally discarded the return value.
Where a function returns a value that intentionally isn't being used, then casting the return value to 'void' satisfies the
requirements of the rules and shows that the discard is intentional.
3) The concern is that all return values should be used, unless explicitly discarded. The concern is not restricted to error reports.
We've noted the point you make regarding 'push_back' and 'emplace_back' and will consider any changes that may be appropriate.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group