Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-4069

Operator overloads should have named alternatives

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Implement alternative method 'xxx' for the operator 'yy'.
    • Highlighting:
      Hide

      Operator overload declaration

      Show
      Operator overload declaration
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      C#
    • Irrelevant for Languages:
      ABAP, C, C++, Cobol, CSS, Flex, HTML, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources
    • FxCop:
      OperatorOverloadsHaveNamedAlternates, CA2225

      Description

      Operator overloading is convenient but unfortunately not portable across languages. To be able to access the same functionality from another language you need to provide an alternate named method following the convention:

      Operator Method Name
      + (binary) Add
      & BitwiseAnd
      | BitwiseOr
      / Divide
      == Equals
      ^ Xor
      > Compare
      >= Compare
      != Equals
      < Compare
      <= Compare
      ! LogicalNot
      % Mod
      * (binary) Multiply
      ~ OnesComplement
      - (binary) Subtract
      - (unary) Negate
      + (unary) Plus

      This rule raises an issue when there is an operator overload without the expected named alternative method.

      Exceptions

      This rule does not raise an issue when the class implementing the comparison operators >, <, >= and <= contains a method named CompareTo.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeanchristophe.collet Jean-Christophe Collet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: