aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-10-11 03:04:15 +0000
committerRichard Stallman <rms@gnu.org>1993-10-11 03:04:15 +0000
commitf1a2b9559f41a54c52fff5e1f3b98c85c5a1b3dd (patch)
treeff4aa76950b231fbb9a31e7a37c3ddfed7de9c45
parentecbc46954235fb3cc8814f02cc65ed6b34988e8a (diff)
downloadgcc-f1a2b9559f41a54c52fff5e1f3b98c85c5a1b3dd.zip
gcc-f1a2b9559f41a54c52fff5e1f3b98c85c5a1b3dd.tar.gz
gcc-f1a2b9559f41a54c52fff5e1f3b98c85c5a1b3dd.tar.bz2
(start_init): Don't set require_constant_elements for scalar types.
(convert_for_assignment): Allow silent conversion to a pointer from an integer 0 that resulted from arithmetic. From-SVN: r5724
-rw-r--r--gcc/c-typeck.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 096c132..d201d3b 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3918,8 +3918,14 @@ convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
{
/* An explicit constant 0 can convert to a pointer,
- but not a 0 that results from casting or folding. */
- if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
+ or one that results from arithmetic, even including
+ a cast to integer type. */
+ if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
+ &&
+ ! (TREE_CODE (rhs) == NOP_EXPR
+ && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
+ && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
+ && integer_zerop (TREE_OPERAND (rhs, 0))))
{
warn_for_assignment ("%s makes pointer from integer without a cast",
get_spelling (errtype), funname, parmnum);
@@ -4792,7 +4798,14 @@ start_init (decl, asmspec_tree, top_level)
if (decl != 0)
{
require_constant_value = TREE_STATIC (decl);
- require_constant_elements = TREE_STATIC (decl) || pedantic;
+ require_constant_elements
+ = ((TREE_STATIC (decl) || pedantic)
+ /* For a scalar, you can always use any value to initialize,
+ even within braces. */
+ && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
+ || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
+ || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
locus = IDENTIFIER_POINTER (DECL_NAME (decl));
constructor_incremental |= TREE_STATIC (decl);
}