From: Joseph Myers Date: Sat, 18 Apr 2009 22:34:10 +0000 (+0100) Subject: re PR c/22367 (constraints on '&' not fully implemented) X-Git-Tag: releases/gcc-4.5.0~6420 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b4b70360f735644f8df105d2057023135367168;p=thirdparty%2Fgcc.git re PR c/22367 (constraints on '&' not fully implemented) PR c/22367 * c-typeck.c (build_unary_op): Check for taking address of expression of type void. testsuite: * gcc.dg/lvalue-6.c, gcc.dg/lvalue-7.c: New tests. From-SVN: r146332 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e1507651c2b5..4035b2c90ebc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2009-04-18 Joseph Myers + + PR c/22367 + * c-typeck.c (build_unary_op): Check for taking address of + expression of type void. + 2009-04-18 Joseph Myers PR c/35210 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 001ea1a5aec3..bacfdc0e8493 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3346,6 +3346,15 @@ build_unary_op (location_t location, case ADDR_EXPR: /* Note that this operation never does default_conversion. */ + /* The operand of unary '&' must be an lvalue (which excludes + expressions of type void), or, in C99, the result of a [] or + unary '*' operator. */ + if (VOID_TYPE_P (TREE_TYPE (arg)) + && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED + && (TREE_CODE (arg) != INDIRECT_REF + || !flag_isoc99)) + pedwarn (location, 0, "taking address of expression of type %"); + /* Let &* cancel out to simplify resulting code. */ if (TREE_CODE (arg) == INDIRECT_REF) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0ccc20a22468..a2b0bb043c3c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-18 Joseph Myers + + PR c/22367 + * gcc.dg/lvalue-6.c, gcc.dg/lvalue-7.c: New tests. + 2009-04-18 Joseph Myers * gcc.dg/cpp/include5.c: New test. diff --git a/gcc/testsuite/gcc.dg/lvalue-6.c b/gcc/testsuite/gcc.dg/lvalue-6.c new file mode 100644 index 000000000000..af69de4df4c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lvalue-6.c @@ -0,0 +1,17 @@ +/* Test constraints on unary '&': PR 22367. */ + +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */ + +extern void v; +void f1 (void) { &v; } /* { dg-error "taking address of expression of type 'void'" } */ + +extern void *pv; +void f2 (void) { &*pv; } /* { dg-warning "dereferencing" } */ +/* { dg-error "taking address of expression of type 'void'" "C90 only error" { target *-*-* } 10 } */ + +extern const void cv; +void f3 (void) { &cv; } + +extern const void *pcv; +void f4 (void) { &*pcv; } /* { dg-warning "dereferencing" } */ diff --git a/gcc/testsuite/gcc.dg/lvalue-7.c b/gcc/testsuite/gcc.dg/lvalue-7.c new file mode 100644 index 000000000000..37964e1cd763 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lvalue-7.c @@ -0,0 +1,16 @@ +/* Test constraints on unary '&': PR 22367. */ + +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ + +extern void v; +void f1 (void) { &v; } /* { dg-error "taking address of expression of type 'void'" } */ + +extern void *pv; +void f2 (void) { &*pv; } /* { dg-warning "dereferencing" } */ + +extern const void cv; +void f3 (void) { &cv; } + +extern const void *pcv; +void f4 (void) { &*pcv; } /* { dg-warning "dereferencing" } */