From 207bf4854d656b1aa84cd244184cfefa5a680f78 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 6 Nov 2001 12:39:36 +0000 Subject: re PR c/461 (non-lvalue arrays) * c-common.c (c_expand_expr_stmt): Apply default conversions to non-lvalue arrays if C99. * c-typeck.c (default_conversion): Split out code handling array-to-pointer and function-to-pointer conversions into a separate default_function_array_conversion function. (default_function_array_conversion): New function. Keep track of whether any NON_LVALUE_EXPRs were stripped. Return non-lvalue arrays unchanged outside C99 mode instead of giving an error for them. (build_component_ref): Use pedantic_non_lvalue when handling COMPOUND_EXPR. Don't handle COND_EXPR specially. (convert_arguments): Use default_function_array_conversion. (build_unary_op): For ADDR_EXPR, take a flag indicating whether non-lvalues are OK. (unary_complex_lvalue): Likewise. (internal_build_compound_expr): Use default_function_array_conversion. Apply default conversions to function in compound expression. (build_c_cast, build_modify_expr, digest_init, build_asm_stmt): Use default_function_array_conversion. * doc/extend.texi: Update documentation of subscripting non-lvalue arrays. Fixes PR c/461. testsuite: * gcc.dg/c90-array-lval-1.c, gcc.dg/c90-array-lval-2.c, gcc.dg/c99-array-lval-1.c, gcc.dg/c99-array-lval-2.c: Remove XFAILs. Adjust expected error texts. * gcc.c-torture/compile/20011106-1.c, gcc.c-torture/compile/20011106-2.c, gcc.dg/c90-array-lval-3.c, gcc.dg/c90-array-lval-4.c, gcc.dg/c90-array-lval-5.c, gcc.dg/c99-array-lval-3.c, gcc.dg/c99-array-lval-4.c, gcc.dg/c99-array-lval-5.c: New tests. From-SVN: r46805 --- gcc/testsuite/gcc.dg/c99-array-lval-5.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/c99-array-lval-5.c (limited to 'gcc/testsuite/gcc.dg/c99-array-lval-5.c') diff --git a/gcc/testsuite/gcc.dg/c99-array-lval-5.c b/gcc/testsuite/gcc.dg/c99-array-lval-5.c new file mode 100644 index 0000000..57e806d --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-array-lval-5.c @@ -0,0 +1,26 @@ +/* Test for non-lvalue arrays: test that the unary '&' operator is not + allowed on them, for both C90 and C99. */ + +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +struct s { char c[1]; }; + +extern struct s foo (void); +struct s a, b, c; +int d; + +void +bar (void) +{ + &((foo ()).c); /* { dg-bogus "warning" "warning in place of error" } */ + &((d ? b : c).c); /* { dg-bogus "warning" "warning in place of error" } */ + &((d, b).c); /* { dg-bogus "warning" "warning in place of error" } */ + &((a = b).c); /* { dg-bogus "warning" "warning in place of error" } */ +} +/* { dg-error "lvalue" "bad address-of" { target *-*-* } 17 } + { dg-error "lvalue" "bad address-of" { target *-*-* } 18 } + { dg-error "lvalue" "bad address-of" { target *-*-* } 19 } + { dg-error "lvalue" "bad address-of" { target *-*-* } 20 } +*/ -- cgit v1.1