[LLVMbugs] [Bug 23404] New: int32_t vs. int64_t vs. long ambiguity

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon May 4 01:34:49 PDT 2015


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

            Bug ID: 23404
           Summary: int32_t vs. int64_t vs. long ambiguity
           Product: clang
           Version: 3.6
          Hardware: Macintosh
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: warp at iki.fi
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider the following program:

//--------------------------------------------------------------------
#include <cstdint>
#include <iostream>

void foo(std::int32_t) { std::cout << "int32_t\n"; }
void foo(std::int64_t) { std::cout << "int64_t\n"; }

int main()
{
    static_assert(sizeof(123L) == 8, "long is not 64-bit");
    foo(123L);
}
//--------------------------------------------------------------------

It produces (with a 64-bit target) the compiler error:

test.cc:11:5: error: call to 'foo' is ambiguous

I see no reason why it should be ambiguous. 123L is unambiguously a 64-bit
literal and should not match std::int32_t.

The literal value being small is not the reason for the error because the exact
same error happens with "foo(0x100000000L)" which shouldn't fit a std::int32_t,
and also with "foo(variable)" where 'variable' is of long type.

Note that "foo(123)" does not cause an error, instead compiling just fine (and
calling the std::int32_t version of the function). Obviously "foo(123LL)" does
not cause an error either. Only "foo(123L)" does.

The error can be circumvented by adding a new version of the function:

void foo(long) { std::cout << "long\n"; }

The problem with this is that I don't think it's a portable program anymore.
That's because if eg. std::int64_t happens to be typedeffed to 'long' in some
other compiler, it will cause a redefinition error. Indeed, if I added eg. this
function:

void foo(long long) { std::cout << "long long\n"; }

I get:

test.cc:7:6: error: redefinition of 'foo'

Is there a reason why a 64-bit 'long' value cannot unambiguously match
std::int64_t?

-- 
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/20150504/b4e68075/attachment.html>


More information about the llvm-bugs mailing list