Skip to content

RULE-7-0-4: false positives on overloaded operator<</operator>> in uninstantiated template bodies #1177

Closed

Description

@castler

Affected rules

  • RULE-7-0-4 ( cpp/misra/inappropriate-bitwise-or-shift-operands )

Description

 InappropriateBitwiseOrShiftOperands.ql  reports operations that do not use the built-in bitwise or shift operators. The overwhelming majority of these are uses of the stream insertion and extraction operators, e.g.  stream << value .

On our codebase ( eclipse-score/communication ) this accounts for 72 of 76 reported violations, i.e. ~95% of the results for this rule are false positives.

Typical messages:

   Shift operator '<<' requires unsigned left operand, but has type 'basic_ostream<char, char_traits<char>> &'.                                                                                          
   Shift operator '<<' requires unsigned left operand, but has type 'unknown'.                                                                                                                           
   Shift operator '<<' requires unsigned right operand, but has type 'auto &&'.                                                                                                                          
   Shift operator '<<' requires unsigned right operand, but has type 'const char[22]'.                       

Example

template<typename ServiceIdType>
std::string ToHexString(const ServiceIdType service_id) {
std::stringstream stream;
// FALSE POSITIVE: reported twice, for the left and the right operand
stream << std::setfill('0') << std::setw(8) << std::hex << service_id;
return stream.str();
}                

Activity

  1. changed the title [-]`RULE-7-0-4`: alse positives on overloaded `operator<<`/`operator>>` in uninstantiated template bodies[/-] [+]`RULE-7-0-4`: false positives on overloaded `operator<<`/`operator>>` in uninstantiated template bodies[/+] on Aug 21, 2026
  2. added a commit that references this issue on Aug 24, 2026
    a0f0606
  3. added a commit that references this issue on Sep 19, 2026
    a7f144a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    false positive/false negativeAn issue related to observed false positives or false negatives.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions