On Sat, 7 Nov 2020, Uecker, Martin wrote:

> In 'gcc.dg/cond-constqual-1.c' we test for the opposite
> behavior for conditional operators. I do not know why.
> We could just invert the test.

That's probably a relic of the old idea that rvalues might actually have 
qualified type in some cases; it seems reasonable to invert the test.

>   t = (const T) { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
>   test (&t);
> }
> 
> Not sure what to do about it, maybe 'convert' is not
> the right function to use.

I think 'convert' is fine, but new code is probably needed in whatever 
implements the optimization for assignment from compound literals so that 
it works when there is a conversion that only changes qualifiers.

> diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
> index 96840377d90..aeacd30badd 100644
> --- a/gcc/c/c-typeck.c
> +++ b/gcc/c/c-typeck.c
> @@ -2080,6 +2080,8 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr 
> exp,
>      exp = default_function_array_conversion (loc, exp);
>    if (!VOID_TYPE_P (TREE_TYPE (exp.value)))
>      exp.value = require_complete_type (loc, exp.value);
> +  if (convert_p && !error_operand_p (exp.value))
> +    exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), 
> TYPE_UNQUALIFIED),
> exp.value);

I think it might be safest to avoid doing any conversion in the case where 
the value is still of array type at this point (C90 non-lvalue arrays).

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to