Repository navigation
fix(clang-tidy): use UNREACHABLE for unreachable paths (RULE-0-0-2) - #1352
Conversation
| << "Could not subtract " << second_address_as_integer << "from" << first_address_as_integer | ||
| << ". Result does not fit into std::ptrdiff_t. Terminating."; | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
There was a problem hiding this comment.
Why is this unreachable? std::ptrdiff_t is signed while std::uintptr_t is unsigned. So you could theoretically have 2 pointers which are further than std::ptrdiff_t::max apart. I think that this is possible in code and also we should be able to write a test for this.
| << first_address_as_integer | ||
| << ". Result does not fit into std::ptrdiff_t. Terminating."; | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
| OfferedStateMachine::State StopOfferedState::StopOffer() | ||
| { | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(0); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
There was a problem hiding this comment.
Why is this unreachable? You can call StopOffer when in StopOfferedState
| << "Unable to find data storage for given event instance. Terminating."; | ||
| SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(false, | ||
| "Unable to find data storage for given event instance."); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE_MESSAGE("Unable to find data storage for given event instance."); |
| // default case and break are necessary to have well-formed switch. | ||
| // coverity[autosar_cpp14_m0_1_1_violation : FALSE] | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(false, "Invalid quality type"); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE_MESSAGE("Invalid quality type"); |
There was a problem hiding this comment.
This is contradicting the comment above
| // This is false positive, the enum has more fields than EVENT and FIELD so we might reach this branch. | ||
| // coverity[autosar_cpp14_m0_1_1_violation : FALSE] | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(false, "Service element type must be EVENT or FIELD"); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE_MESSAGE("Service element type must be EVENT or FIELD"); |
There was a problem hiding this comment.
Why is this unreachable? Contradicts comment above
| // This is false positive, the enum has more fields than EVENT and FIELD so we might reach this branch. | ||
| // coverity[autosar_cpp14_m0_1_1_violation : FALSE] | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(false, "Service element type must be EVENT or FIELD"); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE_MESSAGE("Service element type must be EVENT or FIELD"); |
There was a problem hiding this comment.
Why is this unreachable? Contradicts comment above
| { | ||
| ::score::mw::log::LogFatal("lola") << validation_result.error().UserMessage(); | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
There was a problem hiding this comment.
What is the Validate doing if it can never return an emply result?
| { | ||
| ::score::mw::log::LogFatal("lola") << validation_result.error().UserMessage(); | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
There was a problem hiding this comment.
What is the Validate doing if it can never return an emply result?
| score::mw::log::LogFatal("lola") << "SampleAllocateeTracker destroyed while still holding" << num_allocated | ||
| << "outstanding SampleAllocateePtr instance(s), terminating."; | ||
| SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(false); | ||
| SCORE_LANGUAGE_FUTURECPP_UNREACHABLE(); |
19b74de to
014ee2f
Compare
…able paths Replace ASSERT_PRD(false), ASSERT_PRD(0) and the *_PRD_MESSAGE(false, ...) variants with SCORE_LANGUAGE_FUTURECPP_UNREACHABLE[_MESSAGE]. They express that the path must never be taken and always terminate, like the _PRD variants, without an assertion on a constant condition. Fixes the CodeQL RULE-0-0-2 (invariant condition) findings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not expected Add a comment above each SCORE_LANGUAGE_FUTURECPP_UNREACHABLE[_MESSAGE] introduced for RULE-0-0-2 stating that the path is reachable in principle, why, and that it must not be reached in production. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ffbf5ac
Fixes CodeQL MISRA C++ RULE-0-0-2 (
cpp/misra/invariant-condition) findings by replacing asserts on a constant condition (ASSERT_PRD(false),ASSERT_PRD(0),*_PRD_MESSAGE(false, ...)) withSCORE_LANGUAGE_FUTURECPP_UNREACHABLE[_MESSAGE].Behaviour is unchanged: the
_PRDasserts andUNREACHABLEboth terminate in every assert level. Messages are kept.Not covered (not asserts):
operator<inservice_instance_deployment.cppand two sites intracing_filter_config.cpp.Validated:
--config=cibuild,//score/mw/com/impl/...and//score/memory/shared/...tests pass (244 pass, 3 skipped).