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/52661] New: negative maxint for long long gives warning


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661

             Bug #: 52661
           Summary: negative maxint for long long gives warning
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jmichae3@yahoo.com


Created attachment 26948
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26948
maxint64-bug.cpp, the code which causes the warning

I have tried outputting with <iostream> and I get correct output.
but I get a compiler warning if I use the following constant:
-9223372036854775808LL

//maxint64-bug.cpp
//#include <iostream>
int main(void) {
    long long ll=-9223372036854775808LL;
    //std::cout<<ll;
    return 0;
}
/*
g++ compiles with warning I should not get...
Wed 03/21/2012
22:19:23.42|C:\prj\test\mingw-w64\maxint64-bug|>c:\mingw-w32-bin_i686-mingw_20111127\bin\i686-w64-mingw32-g++.exe
-ls
tdc++ -Wall -W -Wextra -Xlinker -Map=maxint64-bug.map -std=c++11 -Ofast -o
"maxint64-bug.exe" "maxint64-bug.cpp"          2>"errmaxint64-bug"

Wed 03/21/2012 22:19:26.01|C:\prj\test\mingw-w64\maxint64-bug|>type
"errmaxint64-bug"
maxint64-bug.cpp:3:19: warning: integer constant is so large that it is
unsigned [enabled by default]

this bug is in 4.6.2 as well as 4.7.0
this number is a valid integer within the long long range.  but it is on the
boundary.

the valid range of a long long is -9223372036854775808LL..9223372036854775807LL
or -(2^(64-1))..(2^(64-1)-1)
you can verify this with ttcalc.  you can do this with 32-bit and 16-bit and
8-bit signed integers, for instance,
int or long: -(2^(32-1))..(2^(32-1)-1)  
short: -(2^(16-1))..(2^(16-1)-1)
char: -(2^(8-1))..(2^(8-1)-1)

THOSE RANGES WORK.  this particular constant does NOT.
*/


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