CodeQL documentation

Unclear comparison precedence

ID: cpp/comparison-precedence
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - maintainability
   - readability
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds comparison expressions that use 2 or more comparison operators and are not completely parenthesized. It is best to fully parenthesize complex comparison expressions to explicitly define the order of the comparison operators.

Recommendation

Fully parenthesize complex comparison expressions to avoid confusion.

Example

void h() {
	int a, b, c;

	a < b != c; //parenthesize to explicitly define order of operators
	(a < b) < c; //correct: parenthesized to specify order
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy