jarro2783 / cxxopts

Lightweight C++ command line option parser
MIT License
4.16k stars 582 forks source link

Getting a sign-conversion warning/error with clang 14 and CXXOPTS_USE_UNICODE_HELP ON #399

Closed tanja84dk closed 1 year ago

tanja84dk commented 1 year ago

Just wanna inform that I'm receiving a sign-conversion warning/error about when ever I build with CXXOPTS_USE_UNICODE_HELP ON on clang 14 It gives no warnings as soon as I don't build with the CXXOPTS_USE_UNICODE_HELP OFF The version I'm using is the 3.1.1 from releases. compiled with "-g -Werror -Wall -Wextra -pedantic -Wconversion -Wundef -Wshadow -Wno-gnu-zero-variadic-macro-arguments -Wzero-as-null-pointer-constant -std=gnu++20"

It looks like its because legth actually is returning a int32_t and not size_t so it looks like change from signed to unsigned within the defined CXXOPTS_USE_UNICODE in the std::size_t stringLength function.

[build] /home/buildclient/.cache/CPM/cxxopts/34ea97fde3ca260fa6ad09943fe241d2af50025c/cxxopts/include/cxxopts.hpp:236:12: error: implicit conversion changes signedness: 'int32_t' (aka 'int') to 'std::size_t' (aka 'unsigned long') [-Werror,-Wsign-conversion]
[build]   return s.length();
[build]   ~~~~~~ ~~^~~~~~~~
[build] 1 error generated.
jarro2783 commented 1 year ago

Thanks, I'll take a look at that one.

tanja84dk commented 1 year ago

Can confirm that the error/warning has disappeared with the changes there has been made to master

Tried to build https://github.com/jarro2783/cxxopts/commit/120205ac5a61d7e715f184fce0328ac5eb3d6712 still with "CXXOPTS_USE_UNICODE_HELP ON" and also with "CXXOPTS_BUILD_EXAMPLES ON" just to test and the build succeeded with no warnings or errors