[applied] C++ patch to fix arrays of vectors

Aldy Hernandez aldyh@redhat.com
Wed Jun 4 01:03:00 GMT 2003


Jason was kind enough to fix this.  He pre-approved it if it passed 
tests.  It did.  Applied.

Tested on x86-linux.

2003-06-03  Jason Merrill  <jason@redhat.com>

	* cp/cp-tree.h (CP_AGGREGATE_TYPE_P): Accept vectors.

	* cp/decl.c (reshape_init): Handle vectors.

	* testsuite/g++.dg/init/array10.C: New.
	
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.847
diff -c -p -r1.847 cp-tree.h
*** cp/cp-tree.h	18 May 2003 13:40:52 -0000	1.847
--- cp/cp-tree.h	4 Jun 2003 00:58:03 -0000
*************** struct lang_decl GTY(())
*** 2397,2405 ****

      An aggregate is an array or a class with no user-declared
      constructors, no private or protected non-static data members, no
!    base classes, and no virtual functions.  */
   #define CP_AGGREGATE_TYPE_P(TYPE)		\
     (TREE_CODE (TYPE) == ARRAY_TYPE		\
      || (CLASS_TYPE_P (TYPE)			\
          && !CLASSTYPE_NON_AGGREGATE (TYPE)))

--- 2397,2408 ----

      An aggregate is an array or a class with no user-declared
      constructors, no private or protected non-static data members, no
!    base classes, and no virtual functions.
!
!    As an extension, we also treat vectors as aggregates.  */
   #define CP_AGGREGATE_TYPE_P(TYPE)		\
     (TREE_CODE (TYPE) == ARRAY_TYPE		\
+    || TREE_CODE (TYPE) == VECTOR_TYPE		\
      || (CLASS_TYPE_P (TYPE)			\
          && !CLASSTYPE_NON_AGGREGATE (TYPE)))

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1059
diff -c -p -r1.1059 decl.c
*** cp/decl.c	31 May 2003 12:53:41 -0000	1.1059
--- cp/decl.c	4 Jun 2003 00:58:13 -0000
*************** reshape_init (tree type, tree *initp)
*** 7438,7444 ****
     /* If the initializer is brace-enclosed, pull initializers from the
        enclosed elements.  Advance past the brace-enclosed initializer
        now.  */
!   if (TREE_CODE (old_init_value) == CONSTRUCTOR
         && TREE_HAS_CONSTRUCTOR (old_init_value))
       {
         *initp = TREE_CHAIN (old_init);
--- 7438,7445 ----
     /* If the initializer is brace-enclosed, pull initializers from the
        enclosed elements.  Advance past the brace-enclosed initializer
        now.  */
!   if (TREE_CODE (old_init_value) == CONSTRUCTOR
!       && TREE_TYPE (old_init_value) == NULL_TREE
         && TREE_HAS_CONSTRUCTOR (old_init_value))
       {
         *initp = TREE_CHAIN (old_init);
*************** reshape_init (tree type, tree *initp)
*** 7483,7490 ****
        non-empty subaggregate, brace elision is assumed and the
        initializer is considered for the initialization of the first
        member of the subaggregate.  */
!   if (CLASS_TYPE_P (type)
!       && !brace_enclosed_p
         && can_convert_arg (type, TREE_TYPE (old_init_value), 
old_init_value))
       {
         *initp = TREE_CHAIN (old_init);
--- 7484,7490 ----
        non-empty subaggregate, brace elision is assumed and the
        initializer is considered for the initialization of the first
        member of the subaggregate.  */
!   if (!brace_enclosed_p
         && can_convert_arg (type, TREE_TYPE (old_init_value), 
old_init_value))
       {
         *initp = TREE_CHAIN (old_init);
Index: testsuite/g++.dg/init/array10.C
===================================================================
RCS file: testsuite/g++.dg/init/array10.C
diff -N testsuite/g++.dg/init/array10.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/array10.C	4 Jun 2003 00:58:13 -0000
***************
*** 0 ****
--- 1,5 ----
+ // { dg-do compile }
+
+ typedef int __attribute__((mode(V2SI))) vec;
+
+ vec foo[] = { (vec) {1, 2} };



More information about the Gcc-patches mailing list