Skip to content

bugprone-unintended-char-ostream-output reported with sufficient cast #133425

@firewave

Description

@firewave
#include <cstdint>
#include <iostream>

enum E : std::uint8_t {
    E1
};

void f(E e)
{
    std::cout << static_cast<unsigned char>(e);
}
<source>:10:15: warning: 'unsigned char' passed to 'operator<<' outputs as character instead of integer. cast to 'unsigned int' to print numeric value or cast to 'char' to print as character [bugprone-unintended-char-ostream-output]
   10 |     std::cout << static_cast<unsigned char>(e);
      |               ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                  static_cast<unsigned int>(static_cast<unsigned char>(e))

https://godbolt.org/z/vzPoa9jnd

CC @HerrCai0907

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions