view gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* { dg-options "-fdiagnostics-show-caret -Wreturn-local-addr" } */

int *address_of_local (void)
{
  int some_local;
  return &some_local; /* { dg-warning "function returns address of local variable" } */
/* { dg-begin-multiline-output "" }
   return &some_local;
          ^~~~~~~~~~~
   { dg-end-multiline-output "" } */
}

void surplus_return_when_void_1 (void)
{
  return 500; /* { dg-warning "'return' with a value, in function returning void" } */
/* { dg-begin-multiline-output "" }
   return 500;
          ^~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
 void surplus_return_when_void_1 (void)
      ^~~~~~~~~~~~~~~~~~~~~~~~~~
   { dg-end-multiline-output "" } */
}

void surplus_return_when_void_2 (int i, int j)
{
  return i * j; /* { dg-warning "'return' with a value, in function returning void" } */
/* { dg-begin-multiline-output "" }
   return i * j;
          ~~^~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
 void surplus_return_when_void_2 (int i, int j)
      ^~~~~~~~~~~~~~~~~~~~~~~~~~
   { dg-end-multiline-output "" } */
}

int missing_return_value (void)
{
  return; /* { dg-warning "'return' with no value, in function returning non-void" } */
/* { dg-begin-multiline-output "" }
   return;
   ^~~~~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
 int missing_return_value (void)
     ^~~~~~~~~~~~~~~~~~~~
   { dg-end-multiline-output "" } */
/* TODO: ideally we'd underline the return type i.e. "int", but that
   location isn't captured.  */
}