This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/56930] New: regression: pointless -Wconversion warning with sizeof


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]