2009-04-18 Joseph Myers <joseph@codesourcery.com>
+ PR c/22367
+ * c-typeck.c (build_unary_op): Check for taking address of
+ expression of type void.
+
+2009-04-18 Joseph Myers <joseph@codesourcery.com>
+
PR c/35210
* c-typeck.c (build_function_call): Check for calling a function
with qualified void return types. Call require_complete_type when
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 %<void%>");
+
/* Let &* cancel out to simplify resulting code. */
if (TREE_CODE (arg) == INDIRECT_REF)
{
2009-04-18 Joseph Myers <joseph@codesourcery.com>
+ PR c/22367
+ * gcc.dg/lvalue-6.c, gcc.dg/lvalue-7.c: New tests.
+
+2009-04-18 Joseph Myers <joseph@codesourcery.com>
+
* gcc.dg/cpp/include5.c: New test.
2009-04-18 Joseph Myers <joseph@codesourcery.com>
--- /dev/null
+/* 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" } */
--- /dev/null
+/* 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" } */