Commit 10bc1b1b by Joseph Myers Committed by Joseph Myers

re PR c/13519 (typeof(nonconst+const) is const)

	PR c/13519
	* c-typeck.c (composite_type, common_pointer_type): New functions.
	(common_type): Split parts into composite_type and
	common_pointer_type.  Ensure that arithmetic operations return
	unqualified types without attributes.  Don't make composite type
	of signed enum and compatible integer be unsigned.
	(build_conditional_expr, build_binary_op): Use
	common_pointer_type.
	* c-decl.c (merge_decls): Use composite_type.
	* c-tree.h (composite_type): Declare.

testsuite:
	* gcc.c-torture/enum-3.c, gcc.dg/pr13519-1.c: New tests.

From-SVN: r82671
parent ff24b820
2004-06-06 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/13519
* c-typeck.c (composite_type, common_pointer_type): New functions.
(common_type): Split parts into composite_type and
common_pointer_type. Ensure that arithmetic operations return
unqualified types without attributes. Don't make composite type
of signed enum and compatible integer be unsigned.
(build_conditional_expr, build_binary_op): Use
common_pointer_type.
* c-decl.c (merge_decls): Use composite_type.
* c-tree.h (composite_type): Declare.
2004-06-06 Stephane Carrez <stcarrez@nerim.fr>
PR target/14457
......
......@@ -1452,7 +1452,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
/* Merge the data types specified in the two decls. */
TREE_TYPE (newdecl)
= TREE_TYPE (olddecl)
= common_type (newtype, oldtype);
= composite_type (newtype, oldtype);
/* Lay the type out, unless already done. */
if (oldtype != TREE_TYPE (newdecl))
......
......@@ -226,6 +226,7 @@ extern tree c_size_in_bytes (tree);
extern bool c_mark_addressable (tree);
extern void c_incomplete_type_error (tree, tree);
extern tree c_type_promotes_to (tree);
extern tree composite_type (tree, tree);
extern tree build_component_ref (tree, tree);
extern tree build_indirect_ref (tree, const char *);
extern tree build_array_ref (tree, tree);
......
2004-06-06 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/13519
* gcc.c-torture/enum-3.c, gcc.dg/pr13519-1.c: New tests.
2004-06-06 Giovanni Bajo <giovannibajo@gcc.gnu.org>
PR c++/15503
......
/* The composite type of int and an enum compatible with int might be
either of the two types, but it isn't an unsigned type. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
#include <limits.h>
#include <stdio.h>
extern void abort (void);
extern void exit (int);
enum e { a = INT_MIN };
int *p;
enum e *q;
int
main (void)
{
enum e x = a;
q = &x;
if (*(1 ? q : p) > 0)
abort ();
exit (0);
}
/* typeof applied to const+nonconst should be nonconst, as should
typeof applied to other arithmetic expressions. Bug 13519. */
/* Origin: Debian bug report 208981
from Kalle Olavi Niemitalo <kon@iki.fi>, adapted to a testcase by
Joseph Myers <jsm@polyomino.org.uk>. */
/* { dg-do compile } */
/* { dg-options "" } */
void fn(void)
{
int n;
const int c;
{ __typeof__(n) a1; a1=0; }
{ __typeof__(c) a2; a2=0; } /* { dg-error "read-only" "correct error" } */
{ __typeof__((int)n) a3; a3=0; }
{ __typeof__((int)c) a4; a4=0; } /* { dg-bogus "read-only" "bogus error" { xfail *-*-* } } */
{ __typeof__((const int)n) a5; a5=0; } /* { dg-error "read-only" "correct error" { xfail *-*-* } } */
{ __typeof__((const int)c) a6; a6=0; } /* { dg-error "read-only" "correct error" } */
{ __typeof__(0) a7; a7=0; }
{ __typeof__(1) a8; a8=0; }
{ __typeof__(n+n) b0; b0=0; }
{ __typeof__(n+c) b1; b1=0; }
{ __typeof__(c+n) b2; b2=0; }
{ __typeof__(c+c) b3; b3=0; }
{ __typeof__(0+n) c0; c0=0; }
{ __typeof__(0+c) c1; c1=0; }
{ __typeof__(n+0) c2; c2=0; }
{ __typeof__(c+0) c3; c3=0; }
{ __typeof__(1+n) d0; d0=0; }
{ __typeof__(1+c) d1; d1=0; }
{ __typeof__(n+1) d2; d2=0; }
{ __typeof__(c+1) d3; d3=0; }
{ __typeof__(((int)n)+((int)n)) e0; e0=0; }
{ __typeof__(((int)n)+((int)c)) e1; e1=0; }
{ __typeof__(((int)c)+((int)n)) e2; e2=0; }
{ __typeof__(((int)c)+((int)c)) e3; e3=0; }
{ __typeof__(((const int)n)+((const int)n)) f0; f0=0; }
{ __typeof__(((const int)n)+((const int)c)) f1; f1=0; }
{ __typeof__(((const int)c)+((const int)n)) f2; f2=0; }
{ __typeof__(((const int)c)+((const int)c)) f3; f3=0; }
}
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