AGLint icon indicating copy to clipboard operation
AGLint copied to clipboard

Add rule for detecting invalid logical expressions

Open scripthunter7 opened this issue 11 months ago • 0 comments

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.

3. Unnecessary Expressions

  • (A && true) or (A || false)
    • Such expressions are not logically invalid but redundant, as true or false does not change the outcome.

4. Always True (Tautology)

  • (A || !A)
    • This is always true because either A is true, or A is not true (this is an axiom).

5. Disconnected Conditions

  • (A && B && !B)
    • Here, B and !B exclude each other, so the entire expression will always be false, regardless of the value of A.

scripthunter7 avatar Dec 23 '24 16:12 scripthunter7