| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: msg_302.c,v 1.5 2023/04/15 10:53:59 rillig Exp $ */ | | 1 | /* $NetBSD: msg_302.c,v 1.6 2023/04/15 12:47:32 rillig Exp $ */ |
2 | # 3 "msg_302.c" | | 2 | # 3 "msg_302.c" |
3 | | | 3 | |
4 | // Test for message: '%s' returns pointer to automatic object [302] | | 4 | // Test for message: '%s' returns pointer to automatic object [302] |
5 | | | 5 | |
6 | void * | | 6 | void * |
7 | return_arg(int arg) | | 7 | return_arg(int arg) |
8 | { | | 8 | { |
9 | /* expect+1: warning: 'return_arg' returns pointer to automatic object [302] */ | | 9 | /* expect+1: warning: 'return_arg' returns pointer to automatic object [302] */ |
10 | return &arg; | | 10 | return &arg; |
11 | } | | 11 | } |
12 | | | 12 | |
13 | void * | | 13 | void * |
14 | return_local(void) | | 14 | return_local(void) |
| @@ -32,24 +32,32 @@ return_local_array(int x) | | | @@ -32,24 +32,32 @@ return_local_array(int x) |
32 | return &local[3]; | | 32 | return &local[3]; |
33 | case 2: | | 33 | case 2: |
34 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ | | 34 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ |
35 | return 5 + local; | | 35 | return 5 + local; |
36 | case 3: | | 36 | case 3: |
37 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ | | 37 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ |
38 | return local + 5; | | 38 | return local + 5; |
39 | case 4: | | 39 | case 4: |
40 | /* XXX: lint only checks '+' but not '-'. */ | | 40 | /* XXX: lint only checks '+' but not '-'. */ |
41 | return local - -3; | | 41 | return local - -3; |
42 | case 5: | | 42 | case 5: |
43 | /* XXX: lint doesn't track this indirection, but Clang-tidy does. */ | | 43 | /* XXX: lint doesn't track this indirection, but Clang-tidy does. */ |
44 | return indirect; | | 44 | return indirect; |
| | | 45 | case 6: |
| | | 46 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ |
| | | 47 | return (local); |
| | | 48 | case 7: |
| | | 49 | /* C99 6.5.2.5p6 */ |
| | | 50 | /* Neither GCC 10 nor Clang 15 warn about this case. */ |
| | | 51 | /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */ |
| | | 52 | return (char[]){"local string"}; |
45 | default: | | 53 | default: |
46 | return "OK"; | | 54 | return "OK"; |
47 | } | | 55 | } |
48 | } | | 56 | } |
49 | | | 57 | |
50 | void * | | 58 | void * |
51 | return_static(void) | | 59 | return_static(void) |
52 | { | | 60 | { |
53 | static int long_lived = 3; | | 61 | static int long_lived = 3; |
54 | return &long_lived; | | 62 | return &long_lived; |
55 | } | | 63 | } |