658@@ -659,7 +659,8 @@ struct Node {
659 stack.pop_back();
660 }
661 // The final remaining results element is the root result, return it.
662- assert(results.size() == 1);
663+ assert(results.size() >= 1);
why >=
if then you check against ==
?
The assert
is a looser check. If this condition doesn’t hold it will trigger UB on the line right after so we’d rather crash. The CHECK_NONFATAL
check is stricter and as long as the assert holds only applies to the logic, so it’s not necessary to crash the program. Raising an exception to signal the bug to the user is sufficient.
Just for reference, CHECK_NONFATAL
is safe (from an UB perspective) to be used as a drop-in replacement for assert/Assert
(and vice-versa) with only a slight difference: An assertion failure will abort the whole program, and not continue to the next statement. A nonfatal check failure will also not continue to the next statement, but it will just throw an exception and not fatally abort the whole program.