It's an obvious bug, beyond doubt.
The intent of the warning is NOT to warn about all divisions in a program. That would be far too noisy in any reasonable program. Instead, the intent is to warn you when you need to check an argument. In this case, you did check the argument. Hence, the compiler should have noted that, and shut up.
The technical implementation of such a feature is done by labelling variables in code branches with certain attributes. One of the most common attributes is the tri-state "Is null". Before the branch, arg
is an external variable and arg [[Isnull]]
is unknown. But after the check on arg
there are two branches. In the first branch arg [[Isnull]]
is true. In the second branch arg [[Isnull]]
is false.
Now, when it comes to generating divide-by-zero and null pointer warnings, the [[IsNull]
attribute should be checked. If true, you have a severe warning/error. If unknown, you should generate the warning shown above - a potential problem, beyond what the compiler can prove. But in this case, the [[isNull]]
attribute is False. The compiler by the same formal logic as humans, knows that there is no risk.
But how do we know that the compiler is using such an [[Isnull]]
attribute internally? Recall the first paragraph : without it, it would have to either warn always or never. We know it warns sometimes, ergo there must be an [[IsNull]]
attribute.