Expression with identical operands

ID

c.maintainability.redundant_expression

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundant Operation

Language

C / C++

Description

Both operands of this expression are identical, so the result is constant (e.g. x == x is always true, x - x is always zero). This is usually a typo where one operand should differ. Fix the intended operand or remove the redundant expression.

Rationale

Both operands of this expression are identical, so the result is constant (e.g. x == x is always true, x - x is always zero). This is usually a typo where one operand should differ. Fix the intended operand or remove the redundant expression.

The following code illustrates the pattern detected by this rule:

// Adapted from clang-tidy misc-redundant-expression test TestSimpleEquivalent,
// restricted to the operators handled by this rule (==, !=, &&, ||, -).
int TestSimpleEquivalent(int X, int Y) {
    // FLAGGED: Expression with identical operands
    if (X - X) return 1;
    // FLAGGED: Expression with identical operands
    if (X == X) return 1;
    // FLAGGED: Expression with identical operands
    if (X != X) return 1;
    // FLAGGED: Expression with identical operands
    if (X && X) return 1;
    // FLAGGED: Expression with identical operands
    if (X || X) return 1;

    if (X != Y) return 1;
    if (X == Y + 0) return 1;

    return 0;
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved