c++: Implement for namespace statics CWG 2867 - Order of initialization for structure...
[official-gcc.git] / gcc / testsuite / gcc.dg / Wuse-after-free-pr109123.c
blob8e6fc3aa014e1dd6114d93610286685888708094
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wall" } */
4 typedef __SIZE_TYPE__ size_t;
5 extern void *realloc (void *__ptr, size_t __size)
6 __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__alloc_size__ (2)));
7 struct vector_objective;
8 typedef struct vector_objective vector_objective;
9 struct vector_objective { double *_begin; double *_end; double *_capacity; };
10 static inline size_t vector_objective_size(const vector_objective * v) {
11 return v->_end - v->_begin; /* { dg-bogus "used after" } */
13 static inline size_t vector_objective_capacity(const vector_objective * v) {
14 return v->_capacity - v->_begin;
16 static inline void vector_objective_reserve(vector_objective * v, size_t n) {
17 size_t old_capacity = vector_objective_capacity(v);
18 size_t old_size = vector_objective_size(v);
19 if (n > old_capacity) {
20 v->_begin = realloc(v->_begin, sizeof(double) * n);
21 v->_end = v->_begin + old_size;
22 v->_capacity = v->_begin + n;
25 static inline void vector_objective_push_back(vector_objective * v, double x) {
26 if (v->_end == v->_capacity)
27 vector_objective_reserve (v, (vector_objective_capacity (v) == 0) ? 8 : 2 * vector_objective_capacity (v));
28 *(v->_end) = x;
29 v->_end++;
32 typedef struct {
33 vector_objective xy;
34 } eaf_polygon_t;
36 int
37 rectangle_add(eaf_polygon_t * regions, double lx)
39 vector_objective_push_back(&regions->xy, lx);
40 return 0;