AGLint
AGLint copied to clipboard
Add rule for detecting invalid logical expressions
We should check conditions in if preprocessor directive.
A logical expression can be invalid if it is contradictory or always produces the same result regardless of the input. Here are some examples:
1. Self-Contradiction
(A && !A)- This states that "A is true and A is not true" simultaneously, which is logically impossible.
2. Redundancy
(A || A)- This always produces the same result as
A. One of the conditions is unnecessary.
- This always produces the same result as
3. Unnecessary Expressions
(A && true)or(A || false)- Such expressions are not logically invalid but redundant, as
trueorfalsedoes not change the outcome.
- Such expressions are not logically invalid but redundant, as
4. Always True (Tautology)
(A || !A)- This is always true because either
Ais true, orAis not true (this is an axiom).
- This is always true because either
5. Disconnected Conditions
(A && B && !B)- Here,
Band!Bexclude each other, so the entire expression will always be false, regardless of the value ofA.
- Here,