summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/diagnostic-range-bad-return.c
blob: 063fdf1f6360b38177691836e519c6fbad521be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* { 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.  */
}