morganstanley/modern-cpp-kafka

Compilation - Sign conversion errors in log.h

andrewchellis opened this issue · 1 comments

./kafka/Log.h:34:63: error: conversion to ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion]
   34 |         return (level >= 0 && level < numLevels) ? levelNames[level] : invalid;

should static_cast level - guaranteed not to lose information due to conditional

error: conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]
   71 |     char _buf[MAX_CAPACITY];

It seems like https://github.com/morganstanley/modern-cpp-kafka/blob/main/include/kafka/Log.h#L38-L40

template <int MAX_CAPACITY>
class LogBuffer
{

should be adjusted to use size_t MAX_CAPACITY as there is no value in a buffer size < 0

This means LOG_BUFFER_SIZE should probably also be adjusted to size_t from int

@andrewchellis Thank you for raising the issue! We got the "clang-tidy" for static checking, while it seems "clang-tidy" doesn't take effect in this case. Could you please share your build environment? (e.g. compiler, options for warnings, etc)