This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR c++/26884
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Mark Shinwell <shinwell at codesourcery dot com>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 09 Oct 2006 20:31:12 -0700
- Subject: Re: [PATCH] Fix PR c++/26884
- References: <452651A5.1090404@codesourcery.com>
Mark Shinwell wrote:
2006-10-06 Mark Shinwell <shinwell@codesourcery.com>
PR c++/26884
* cp/typeck2.c (digest_init): Raise error upon attempts to
initialize arrays with variables.
Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c (revision 117455)
+++ gcc/cp/typeck2.c (working copy)
@@ -733,6 +733,14 @@ digest_init (tree type, tree init)
return error_mark_node;
}
+
+ if (TREE_CODE (type) == ARRAY_TYPE
+ && (TREE_CODE (init) == VAR_DECL || TREE_CODE (init) ==
PARM_DECL))
+ {
+ error ("cannot initialize array with a variable");
+ return error_mark_node;
+ }
+
I think:
array must be initialized with brace-enclosed initializer
would be better. I also suspect that there are cases you will miss, like:
int b[2] = x->a;
That's neither a VAR_DECL or a PARM_DECL. What happens if you issue the
error whenever INIT is not a CONSTRUCTOR? (The representation for a
brace-enclosed initializer?)
Thanks,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713