gcc warning about return value truncation

Yubin Ruan ablacktshirt@gmail.com
Sun Dec 29 05:12:00 GMT 2019

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


More information about the Gcc-help mailing list