[llvm-bugs] [Bug 30605] New: A long long constant is out of range

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 3 16:45:43 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=30605

            Bug ID: 30605
           Summary: A long long constant is out of range
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: iliyaaizin at mail.tau.ac.il
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

In the following code the "<=" expression is being evaluated as false:
///////////////////////////////////
#include <stdio.h>

int main()
{
    short  sh = 9L;
    unsigned int ui1 = (sh <= 0xD48FBCB67A80957DLL);
    printf("%X\n", ui1); 
}
////////////////////////////////////
According to C++11 standard 2.14.2 [lex.icon]: hexadecimal constant suffixed
with "LL" that does not "fit" into long long int, but does "fit" into unsigned
long long int, should be represented by the latter.
In this case our constant: 0xD48FBCB67A80957D < 2^64 - 1
That means that it can be represented by unsigned long long int, and 
the "<=" expression should be evaluated as true;

The command used to compile is: clang file.cpp -std=c++11 -o file.exe
Compiler version:
clang version 3.8.1 (branches/release_38)
Target: i686-pc-windows-msvc
Thread model: posix

The compiler prints out the following warning:
//////////////////////////////////////////////////////
clang+vs.cpp:8:25: warning: comparison of constant -3130075724073888387 with
expression of type 'short' is always false
      [-Wtautological-constant-out-of-range-compare]
        unsigned int ui1 = (sh <= 0xD48FBCB67A80957DLL);
                            ~~ ^  ~~~~~~~~~~~~~~~~~~~~
1 warning generated.
///////////////////////////////////////////////////////////

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161003/f7979758/attachment.html>


More information about the llvm-bugs mailing list