[PATCH,c++] use XALLOCAVEC in the C++ front-end

Jason Merrill jason@redhat.com
Tue Jun 8 14:06:00 GMT 2010


On 06/06/2010 08:52 PM, Nathan Froyd wrote:
> Just a minor cleanup noticed while browsing around.
>
> There's still one call that seems like it ought to be replaceable: in
> semantics.c:finish_asm_stmt, we have:
>
>        oconstraints = (const char **) alloca (noutputs * sizeof (char *));
>
> But changing this to:
>
>        oconstraints = (const char **) XALLOCAVEC (char *, noutputs);
>
> gives the error:
>
> semantics.c: In function ‘finish_asm_stmt’:
> semantics.c:1223:7: error: new ‘const’ qualifier in middle of multi-level non-const cast is unsafe [-Werror=cast-qual]
>
> which I don't understand, because the cast is not in the "middle" of
> anything.  Is this a bug in the cast checking?

The error message is unclear, but the issue is that converting from 
char** to char const** is unsafe, while converting to char const*const* 
is safe.

Just use XALLOCAVEC(const char *, noutputs) with no extra cast.

Jason



More information about the Gcc-patches mailing list