1 /* Exercise basic C-only cases of -Wdangling-pointer.
3 { dg-options "-O0 -Wall" }
4 { dg-require-effective-target alloca } */
6 typedef __SIZE_TYPE__
size_t;
8 extern void* memchr (const void*, int, size_t);
9 extern char* strchr (const char*, int);
11 void sink (const void*, ...);
14 void nowarn_compound_literal (int i
)
17 int *p
= (int[]){ 1, 2, 3 };
21 int *q
= (int[]){ 1, 2, 3 };
26 int *p
= __builtin_memchr ((int[]){ 1, 2, 3 }, 2, 3 * sizeof *p
);
30 int *p
= __builtin_memchr ((int[]){ i
, i
+ 1 }, 3, 2 * sizeof *p
);
36 void warn_compound_literal (int i
)
40 p
= (int[]){ 1, 2, 3 }; // { dg-message "unnamed temporary" },
42 sink (p
); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
46 (int[]){ 1, 2, 3 }; // { dg-message "unnamed temporary" },
49 sink (p
); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
52 (int[]){ 1, 2, 3 }, // { dg-message "unnamed temporary" }
55 sink (p
); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
59 (int[]){ i
, i
+ 1 },// { dg-message "unnamed temporary" }
62 sink (p
); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
66 void warn_store_compound_literal (int **p
)
68 int *q
= (int[]) { 1, 2, 3 };
69 p
[0] = q
; // { dg-warning "storing the address" }
72 void warn_store_vla (int n
, int **p
)
75 p
[1] = &a
[1]; // { dg-warning "-Wdangling-pointer" "pr??????" { xfail *-*-* } }