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: unassig...@gcc.gnu.org
        ReportedBy: jens.mau...@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.

Reply via email to