[LLVMbugs] [Bug 16983] New: decltype(-9223372036854775808) is unsigned instead of signed

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 23 11:27:52 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16983

            Bug ID: 16983
           Summary: decltype(-9223372036854775808) is unsigned instead of
                    signed
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hhinnant at apple.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

#include <limits>
#include <memory>
#include <iostream>
#include <cxxabi.h>
#include <cstdlib>

template <typename T>
std::string
type_name()
{
    typedef typename std::remove_reference<T>::type TR;
    std::unique_ptr<char, void(*)(void*)> own
           (
                abi::__cxa_demangle(typeid(TR).name(), nullptr,
                                           nullptr, nullptr),
                std::free
           );
    std::string r = own != nullptr ? own.get() : typeid(TR).name();
    if (std::is_const<TR>::value)
        r += " const";
    if (std::is_volatile<TR>::value)
        r += " volatile";
    if (std::is_lvalue_reference<T>::value)
        r += "&";
    else if (std::is_rvalue_reference<T>::value)
        r += "&&";
    return r;
}

int
main()
{
    std::cout << std::numeric_limits<long long>::min() << '\n';
    std::cout << -9223372036854775808 << '\n';
    std::cout << static_cast<long long>(0x8000000000000000) << '\n';
    std::cout << type_name<decltype(-9223372036854775808)>() << '\n';
}

I expect this program to compile and output:


-9223372036854775808
-9223372036854775808
-9223372036854775808
long long


or:


-9223372036854775808
-9223372036854775808
-9223372036854775808
long

(latter ok only in 64 bit mode).

Instead I'm getting a warning:


test.cpp:35:19: warning: integer constant is so large that it is unsigned
    std::cout << -9223372036854775808 << '\n';
                  ^
test.cpp:37:38: warning: integer constant is so large that it is unsigned
    std::cout << type_name<decltype(-9223372036854775808)>() << '\n';
                                     ^
2 warnings generated.

And the output is:

-9223372036854775808
9223372036854775808
-9223372036854775808
unsigned long long

-- 
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/20130823/3fe3cf16/attachment.html>


More information about the llvm-bugs mailing list