[Bug tree-optimization/100197] g++ emits spurious Wstring-compare warnings on strcmp()
rajpal.gusain at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jul 28 12:28:20 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100197
--- Comment #2 from Rajpal Singh <rajpal.gusain at gmail dot com> ---
I also get similar error when one of the argument string is constant and I
believe it's related. I tried it with g++ 11.2
'int strncmp(const char*, const char*, size_t)' of strings of length 1 and 6
and bound of 6 evaluates to nonzero [-Werror=string-compare]
if ((std::strncmp(tmp, "define", 6) == 0) && (std::isspace(*(tmp+6)))) {
In no possible way, length of tmp can be 1 and error is definitely spurious and
it's only with -O3 and -Wall.
Moreover, Clang can compile it fine without any issue with same optimization
level.
More information about the Gcc-bugs
mailing list