The assert
macro is used primarily for debugging purposes. It allows developers to test assumptions in their code and have the program
automatically terminate with a diagnostic if an assumption is found to be false.
This rule raises an issue if an assert
cannot be false because its value is hard-coded as true.
The following assertions will never emit a diagnostic:
assert(true); // Noncompliant
assert(1); // Noncompliant
assert("Message"); // Noncompliant: the address of this string literal is never nullptr
They are usually either typos or dead code and should be fixed or removed:
assert(isEven); // checks that isEven is true
assert(false); // interrupts execution
assert(!"Message") // interrupts execution with a message