[PATCH] Fix PR c/11658

Joseph S. Myers jsm@polyomino.org.uk
Mon Feb 2 14:18:00 GMT 2004


On Mon, 2 Feb 2004, Bonzini wrote:

> This adds a C/ObjectiveC langhook and uses it throughout
> c-parse.in.

Why not in c-typeck.c as well?  Why not in c-convert.c?

> +tree
> +c_objc_common_truthvalue_conversion (tree expr)
> +{
> +  switch (TREE_CODE (TREE_TYPE (expr)))
> +    {
> +    case RECORD_TYPE:
> +      error ("struct type value used where scalar is required");
> +      return error_mark_node;
> +
> +    case UNION_TYPE:
> +      error ("union type value used where scalar is required");
> +      return error_mark_node;
> +
> +    default:
> +      break;
> +    }

And what about ARRAY_TYPE?  In C90 mode, non-lvalue arrays can occur here,
and are just as invalid.  (You do of course need to ensure that 
default_conversion or default_function_array_conversion has been applied 
before this function to avoid problems of an array being passed in that 
should first have been converted to a pointer.)

struct s { char c[1]; };
struct s f(void);
int foo(void) { if (f().c) return 1; else return 0; }

and

struct s { char c[1]; };
struct s f(void);
int foo(void) { return !f().c; }

should both yield a meaningful error in C90 mode (and be silently accepted
in C99 mode); at present they have the bad error in C90 mode that this PR
was about.

While

struct s { char c[1]; };
struct s a;
int foo(void) { return (_Bool)a; }

should yield a meaningful error unconditionally, but at present it gives

w.c: In function `foo':
w.c:3: error: invalid operands to binary !=
w.c:3: internal compiler error: tree check: expected class 't', have 'x' (error_mark) in fold, at fold-const.c:5476

You also need testcases covering both these cases and the various other 
instances of bad error messages, that pass with the new error message but 
fail with the old.  (For each present c_common_truthvalue_conversion call, 
work out whether structs/unions/non-lvalue arrays could be passed in.  If 
so, provide a testcase for each case, struct/union/non-lvalue array.)

-- 
Joseph S. Myers
jsm@polyomino.org.uk



More information about the Gcc-patches mailing list