https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91215

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also read https://gcc.gnu.org/gcc-8/porting_to.html :
-Wreturn-type is enabled by default
G++ now assumes that control never reaches the end of a non-void function (i.e.
without reaching a return statement). This means that you should always pay
attention to -Wreturn-type warnings, as they indicate code that can misbehave
when optimized.

To tell the compiler that control can never reach the end of a function (e.g.
because all callers enforce its preconditions) you can suppress -Wreturn-type
warnings by adding __builtin_unreachable:


      char signchar(int i) // precondition: i != 0
      {
        if (i > 0)
          return '+';
        else if (i < 0)
          return '-';
        __builtin_unreachable();
      }

Because -Wreturn-type is now enabled by default, G++ will warn if main is
declared with an implicit int return type (which is non-standard but allowed by
GCC). To avoid the warning simply add a return type to main, which makes the
code more portable anyway.

Reply via email to