You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, the latest devel of Catch2 raises a warning on g++ 12.
conversion to ‘std::size_t’ {aka ‘long unsigned int’} from ‘long int’ may change the sign of the result
This warning was introduced a few days ago by PR #2540
File catch_tostring.hpp line 46:
inline std::size_tcatch_strnlen(constchar *str, std::size_t n) {
auto ret = std::char_traits<char>::find(str, n, '\0');
if (ret != nullptr) {
return ret - str; // <-- Here !
}
return n;
}
Expected behavior
Catch2 builds without warnings.
Reproduction steps
Build Catch2 with g++ .
Platform information:
g++ version 12.1.0 (Ubuntu 12.1.0-2ubuntu1~22.04)
Possible fixes
Change the return type of catch_strnlen to std::ptrdiff_t. This would prevent to return n without a cast to std::ptrdiff_t.
Explicitly cast the result to std::size_t.
returnstatic_cast<std::size_t>(ret - str);
This should be relatively safe as str should never be greater than ret. In my opinion this is the way to go.
Describe the bug
Hello, the latest devel of Catch2 raises a warning on g++ 12.
conversion to ‘std::size_t’ {aka ‘long unsigned int’} from ‘long int’ may change the sign of the result
This warning was introduced a few days ago by PR #2540
File
catch_tostring.hpp
line 46:Expected behavior
Catch2 builds without warnings.
Reproduction steps
Build Catch2 with g++ .
Platform information:
g++ version 12.1.0 (Ubuntu 12.1.0-2ubuntu1~22.04)
Possible fixes
catch_strnlen
tostd::ptrdiff_t
. This would prevent to returnn
without a cast tostd::ptrdiff_t
.std::size_t
.This should be relatively safe as
str
should never be greater thanret
. In my opinion this is the way to go.@rkaminsk what do you think ?
The text was updated successfully, but these errors were encountered: