<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - int32_t vs. int64_t vs. long ambiguity"
   href="https://llvm.org/bugs/show_bug.cgi?id=23404">23404</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>int32_t vs. int64_t vs. long ambiguity
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>warp@iki.fi
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>