public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc warning about return value truncation
@ 2019-12-29  5:12 Yubin Ruan
  2019-12-29  6:28 ` Liu Hao
  0 siblings, 1 reply; 3+ messages in thread
From: Yubin Ruan @ 2019-12-29  5:12 UTC (permalink / raw)
  To: gcc-help

Is there any gcc flag to warn about this?

#include <iostream>
#include <cstdint>

int16_t func() {
    int32_t num = INT32_MAX;
    std::cout << "func() called " << num << std::endl;
    return num;
}

int main()
{
    int32_t val = func();
    std::cout << "return value is " << val << std::endl;
}

The return value of func() was truncated because the return type is
accidentally written as int16_t

Thanks,
Yubin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-02  5:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-29  5:12 gcc warning about return value truncation Yubin Ruan
2019-12-29  6:28 ` Liu Hao
2020-01-02  5:37   ` Yubin Ruan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).