As you've already quoted, Rule A5-1-1
says
Rule A5-1-1 (required, implementation, partially automated)Literal
values shall not be used apart from type initialization,
otherwise symbolic names shall be used instead.
(source)
The idea behind this rule is that you should not use magic constants, i.e., don't write something like
// 100 is a magic constant. It's not clear what the next line means without comments.
if (list.size() > 100) {
std::cout << "error!";
} else {
std::cout << "everything ok!";
}
but rather, write
static constexpr auto maximum_allowed_size = 100;
// The next line speaks for itself: "if list is bigger than allowed ..."
if (list.size() > maximum_allowed_size) {
std::cout << "error!";
} else {
std::cout << "everything ok!";
}
This extra constant increases readability in most cases.
Since nullptr
is a literal and you use that literal nullptr
for something else than "type initialization", your code violates that rule A5-1-1.
I don't know if autosar intentionally discourages the use of literal nullptr
, I personally don't see a reason why one should do this. Maybe it has been overseen (should be an exception).
You can rephrase your code to silence the checker:
if (timing_info) // implicitly convert pointer to bool
as that variant apparently makes the checker unhappy, too, here is another variant:
if (!!timing_info) // convert pointer to bool using double negation
You could also use casts, but I wouldn't do that. Frankly speaking, I like the original variant (if (nullptr != timing_info)
) most.