This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: Add -Wcast-qual to the bootstrap warning flags
On Mon, Sep 24, 2007 at 10:35:45AM -0400, Kaveh R. GHAZI wrote:
> On Sun, 23 Sep 2007, Andrew Pinski wrote:
>
> > On 9/23/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> >
> > > + asprintf (CONST_CAST(char **, &m68k_library_id_string),
> > ^
> > Missing space. Also this looks wrong anyways.
>
> What do you think is wrong with this exactly? The m68k_library_id_string
> variable is a const object that's being initialized here in asprintf.
> Initializing const objects is one of the legitimate cases I've enumerated
> for using CONST_CAST. And as I mentioned I did "make cc1" cross-targetted
> to m68k-unknown-linux-gnu (among many others) to ensure I didn't introduce
> a typo.
I don't think this is legitimate. You should simply:
char *temp;
asprintf (&temp, ....);
m68k_library_id_string = temp;
i.e. completely prepare the object as non-const and only when it is
fully prepared store address of the temp object into the const char *
var.
The asprintf call does no error checking btw, it can fail e.g. if malloc
fails (probably that's the only reason when format string is %d).
So it should be checked as well.
Jakub