This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80157] New: Spurious "Wsign-conversion" warning with const, size_t, array.
- From: "ian at geometrian dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 23 Mar 2017 01:19:04 +0000
- Subject: [Bug c++/80157] New: Spurious "Wsign-conversion" warning with const, size_t, array.
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80157
Bug ID: 80157
Summary: Spurious "Wsign-conversion" warning with const,
size_t, array.
Product: gcc
Version: 7.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ian at geometrian dot com
Target Milestone: ---
Minimal example (compile GCC >= ~6.1 with -Wsign-conversion):
#include <cstdlib>
bool f(size_t const xy[2], int z) {
return xy[0] + xy[1] < static_cast<size_t>(z);
}
Produces an erroneous warning:
<source>: In function 'bool f(const size_t*, int)':
<source>:3:25: warning: conversion to 'long unsigned int' from 'int' may
change the sign of the result [-Wsign-conversion]
return xy[0] + xy[1] < static_cast<size_t>(z);
^~~~~~~~~~~~~~~~~~~~~~
Compiler exited with result code 0
Taking the const out, using unsigned, or passing x and y separately rather than
as an array resolves the warning. Doesn't occur on Clang, MSVC, or earlier
GCC.
May be related to bug 66170.