Commit 2b4b7036 by Joseph Myers Committed by Joseph Myers

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
parent 5cf217ff
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
......
......@@ -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 %<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>
......
/* 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" } */
/* 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" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment