[Bug c++/56930] New: regression: pointless -Wconversion warning with sizeof
jens.maurer at gmx dot net
gcc-bugzilla@gcc.gnu.org
Fri Apr 12 07:11:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56930
Bug #: 56930
Summary: regression: pointless -Wconversion warning with sizeof
Classification: Unclassified
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jens.maurer@gmx.net
int main()
{
int x = sizeof(int);
int y { sizeof(int) };
}
$ g++ -Wconversion -std=c++11 conv.cc
conv.cc: In function ‘int main()’:
conv.cc:3:17: warning: conversion to ‘int’ from ‘long unsigned int’ may alter
its value [-Wconversion]
int x = sizeof(int);
^
gcc 4.7.x didn't warn about this case, and rightly so: There should be no
conversion warnings triggered if the compiler can detect that the value in
question is constant and no narrowing actually happens.
conv.cc:4:17: warning: conversion to ‘int’ from ‘long unsigned int’ may alter
its value [-Wconversion]
int y { sizeof(int) };
^
The warning in this case is even more confusing: The compiler should generate a
language-mandated diagnostic if narrowing a non-constant, but the warning is
just besides the point at all.
More information about the Gcc-bugs
mailing list