0

I'm porting our C++ application from ARM32 Linux to ARM64 Linux. I'm not sure if there is code snippets in our application such as

int i;
long l;
...
i = (int)l;
i = static_cast<int>(l);

which doesn't (normally) have any problems on a 32-bit platform, but may have on a 64-bit platform.

Is there a GCC command line option that detects this and then issues a warning?

xiaokaoy
  • 1,608
  • 3
  • 15
  • 27
  • [Is there a gcc flag to catch integer truncation?](https://stackoverflow.com/q/22198305/995714) – phuclv Jul 31 '20 at 04:36
  • The casting turns off any smarts the compiler could have applied to the situation. All is now legal by divine fiat. If anything can catch this, it's not Wconversion. – user4581301 Jul 31 '20 at 05:12
  • 1
    Since these are **explicit** cast, the compiler is deliberately silenced. And because the casts are explicit, you can use any search tool to find the places. That's life as a developer: Sometimes you need to do it the hard way by code inspection. -- BTW, 1. avoid C casts in C++, and 2. use the types from "stdint.h" (or "cstdint") or even better `i = l & 0xFFFF;` to show the intent. – the busybee Jul 31 '20 at 06:09
  • This is the kind of thing a static analyzer could do rather easily. – cdhowie Aug 01 '20 at 05:56

0 Answers0