[C++][Cortex-M7] Ambiguous call of overloaded function fn(int): fn(int32_t) vs fn(int64_t)

Asked by Ladislav Vadkerti

Compilation of C++ code:

#include <cstdint>

int fn(int32_t x)
{
  return (int)x;
}

int fn(int64_t x)
{
  return (int)x;
}

extern "C" void _exit(int code)
{
  while (1) {}
}

int main(void)
{
  return fn(3);
}

reports an error:

gcc-arm-none-eabi-7-2017-q4-major-win32\bin\arm-none-eabi-c++.exe -mcpu=cortex-m7 main.cpp
main.cpp: In function 'int main()':
main.cpp:20:14: error: call of overloaded 'fn(int)' is ambiguous
   return fn(3);
              ^
main.cpp:3:5: note: candidate: int fn(int32_t)
 int fn(int32_t x)
     ^~
main.cpp:8:5: note: candidate: int fn(int64_t)
 int fn(int64_t x)
     ^~

Isn't the int32_t variant the obvious one to select on Cortex-M7 (its core registers are 32-bit)? At least IAR compiler selects that one. I'm writing a portable code and I would like to have the correct function selected automatically.

Question information

Language:
English Edit question
Status:
Expired
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.