Skip to content

Invalid string name returned on uint8_t-derived enum with entries larger than 0x7F #24

Description

@rndtrash

Compiler: gcc (Ubuntu 15.2.0-4ubuntu4) 15.2.0, C++ version set to 20.

Here is a minimal reproducible example of the issue:

#include <cstdint>
#include <iostream>
#include <fix8/conjure_enum.hpp>

template <FIX8::valid_enum T>
std::string enum_to_string(T value)
{
    return std::string(FIX8::conjure_enum<T>::enum_to_string(value));
}

enum Repro : uint8_t {
	kExpected = 0x01,
	kInvalid = 0x80,
};

int main() {
    const auto val = Repro::kExpected;
    std::cout << "The name of " << +static_cast<uint8_t>(val)
    	<< " is " << enum_to_string(val) << std::endl;

    return 0;
}

Expected output:

The name of 1 is kExpected

Got:

The name of 1 is kInvalid

If kInvalid is set to anything less (like 0x7F or 0x10), then the program above works as expected.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions