This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Pedro Alves <palves at redhat dot com>, gdb-patches at sourceware dot org
- Date: Mon, 26 Oct 2015 22:34:53 -0400
- Subject: Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
- Authentication-results: sourceware.org; auth=none
- References: <1445831362-18789-1-git-send-email-simon dot marchi at polymtl dot ca> <1445831362-18789-2-git-send-email-simon dot marchi at polymtl dot ca> <562E59DF dot 9040407 at redhat dot com>
On 26/10/15 12:50 PM, Pedro Alves wrote:
> On 10/26/2015 03:49 AM, Simon Marchi wrote:
>> The assignment requires a cast in C++.
>>
>> gdb/ChangeLog:
>>
>> * ada-lang.h (GROW_VECT): Add cast.
>> ---
>> gdb/ada-lang.h | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
>> index 62896f1..32c4b55 100644
>> --- a/gdb/ada-lang.h
>> +++ b/gdb/ada-lang.h
>> @@ -147,7 +147,7 @@ struct ada_task_info
>> least M objects, updating V and S as necessary. */
>>
>> #define GROW_VECT(v, s, m) \
>> - if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
>> + if ((s) < (m)) (v) = (typeof (v)) grow_vect (v, &(s), m, sizeof *(v));
>>
>
> typeof in C is a GCC extension. Probably not all compilers support it.
>
> In my branch I just have:
>
> #define GROW_VECT(v, s, m) \
> - if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
> + if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
>
> Because that works for all current uses of GROW_VECT.
>
> If we wanted to make this work for random types, then we could add
> a type parameter to the GROW_VECT macro, like:
>
> - #define GROW_VECT(v, s, m) \
> - if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
> + #define GROW_VECT(t, v, s, m) \
> + if ((s) < (m)) (v) = (t *) grow_vect (v, &(s), m, sizeof *(v));
>
> Not sure it's worth it though. It then raises the question of
> "why not replace this home grown GROW_VECT stuff with a VEC instead".
>
> Thanks,
> Pedro Alves
I thought about changing it for a proper VEC, but it's not really in the scope of
the C++ changes. If I side-track on things like this, it will take an eternity!
And I feel that at this moment, it would be a risk of introducing bugs without
added value.
Is it ok if I simply push your version that adds the (char *) in the macro? It
seems like the most efficient fix given the situation.