https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107813

            Bug ID: 107813
           Summary: Enum with underlying type uint8_t bad promotion for
                    unsigned char
           Product: gcc
           Version: og10 (devel/omp/gcc-10)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gdrzewo at gmail dot com
  Target Milestone: ---

After migration from GCC9 to GCC10+ encountered the problem with printing
underlying types for enum with uint8_t. Below is minimal reproduction. Flooder
is a kind of wrapper for ostream used for logger.

#include <iostream>

enum TEnum: uint8_t {
    Kot = 67
};

struct Flooder
{
    Flooder(std::ostream& oo): o(oo) {};

    std::ostream& o;

    template <typename T>
    Flooder& operator<<(const T& t)
    {
        this->o << t;
        return *this;
    }
};

template<>
Flooder& Flooder::operator<<(const unsigned char& c) {
    o << static_cast<unsigned int>(c);
    return *this;
}

int main() {
    Flooder f(std::cout);

    auto cat = TEnum::Kot;
    unsigned char dog = 'D';

    std::cout << "first is enum uint8_t, second is unsigned char type, both
should be numbers" << std::endl;

    f << cat << " vs " << dog << "\n\r";

    return 0;
}

Std out 
(gcc9)
first is enum uint8_t, second is unsigned char type, both should be numbers
67 vs 68

(gcc10)
first is enum uint8_t, second is unsigned char type, both should be numbers
C vs 68

Reply via email to