This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR c++/80544 strip cv-quals from cast results


On 25/05/17 16:11 +0200, Jakub Jelinek wrote:
On Thu, May 25, 2017 at 03:02:42PM +0100, Jonathan Wakely wrote:
On 25/05/17 11:07 +0100, Jonathan Wakely wrote:
> On 25/05/17 10:05 +0200, Andreas Schwab wrote:
> > ../../gcc/ada/gcc-interface/utils2.c: In function 'int compare_elmt_bitpos(const void*, const void*)':
> > ../../gcc/ada/gcc-interface/utils2.c:1937:73: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
> >  const constructor_elt * const elmt1 = (const constructor_elt * const) rt1;
> >                                                                        ^~~
> > ../../gcc/ada/gcc-interface/utils2.c:1938:73: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
> >  const constructor_elt * const elmt2 = (const constructor_elt * const) rt2;
>
> I'm testing this obvious fix.

Committed as r248458 because it gets bootstrap past the error above,
although now Ada fails for me with:

/home/jwakely/src/gcc/bootstrap/./gcc/xgcc -B/home/jwakely/src/gcc/bootstrap/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include    -c -g -O2 -m32 -fpic  -W -Wall -gnatpg -nostdinc -m32  s-regpat.adb -o s-regpat.o

raised STORAGE_ERROR : stack overflow or erroneous memory access
../gcc-interface/Makefile:296: recipe for target 's-regpat.o' failed


> diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c
> index fc6f1b8..cd37791 100644
> --- a/gcc/ada/gcc-interface/utils2.c
> +++ b/gcc/ada/gcc-interface/utils2.c
> @@ -1934,8 +1934,8 @@ build_call_raise_range (int msg, Node_Id gnat_node, char kind,
> static int
> compare_elmt_bitpos (const PTR rt1, const PTR rt2)
> {
> -  const constructor_elt * const elmt1 = (const constructor_elt * const) rt1;
> -  const constructor_elt * const elmt2 = (const constructor_elt * const) rt2;
> +  const constructor_elt * const elmt1 = (const constructor_elt *) rt1;
> +  const constructor_elt * const elmt2 = (const constructor_elt *) rt2;
>   const_tree const field1 = elmt1->index;
>   const_tree const field2 = elmt2->index;
>   const int ret

So, what can one do with typeof or similar to avoid the warning?

void
foo (const void *p)
{
 const int *const q = (const int *const) p;
 typeof (q) r = (typeof (q)) p;
 (void) q;
 (void) r;
}

I'd probably write that like this instead:

void
foo (const void *p)
{
 typedef const int* ptr_type;
 ptr_type const q = (ptr_type) p;
 ptr_type const r = (ptr_type) p;
 (void) q;
 (void) r;
}

It names the type only once, not twice as in your example, and doesn't
need to use typeof to refer to that type again.

The variables p and q are defined const, which is what's wanted. The
cast is to ptr_type, not ptr_type const.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]