Skip to content

hexify() function emits conversion warning #270

@dtoma

Description

@dtoma

Hello,

Using gcc 6.1.0.

Compilation error (-Wconversion -Werror):

./deps/json.hpp:9995:25:   required from here
./deps/json.hpp:5957:72: error: conversion to 'char' from 'int' may alter its value [-Werror=conversion]
                             : ('a' + static_cast<char>((v - 10) & 0x1f));
                                                                        ^
./deps/json.hpp:5957:72: error: conversion to 'char' from 'int' may alter its value [-Werror=conversion]

hexify:

const auto hexify = [](const int v) -> char
{
  return (v < 10)
  ? ('0' + static_cast<char>(v))
  : ('a' + static_cast<char>((v - 10) & 0x1f));
};

Could be written as something like:

const auto hexify = [](const int v) -> char
{
    static const std::array<char, 16> hex = { '0', '1', '2', '3',
                                              '4', '5', '6', '7',
                                              '8', '9', 'a', 'b',
                                              'c', 'd', 'e', 'f' };
    return hex[v];
};

Would you be interested in a PR for such a change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions