[gnu.g++.bug] Hacked patch for array subscripting

schmidt%siam.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt") (01/02/89)

Hi,

   g++ 1.32 does not correctly handle the communtativity of array and
pointer indexing, i.e., A [ 0 ] == 0 [ A ]; I believe the following
patch fixes this temporarily.  I've tested it a little, but I don't
know if it breaks something else.

   Here's an example of what *didn't* compile before, and now does:

----------------------------------------
main ( ) {
   typedef int VEC [ 20 ];
   typedef VEC ( *PTA );

   VEC a [ 10 ];
   PTA ap = a;
   
   0 [ ap ] [ 0 ] = 10000; // yikes, this is valid!
   printf ( " * 0 [ ap ] = %d\n", * 0 [ ap ] ); // so's this!
}
----------------------------------------

Here are the original diagnostics:

----------------------------------------
g++ version 1.32.0
 /usr/public/lib/g++/gcc-cpp -+ -v -I/cd/ua/schmidt/include/ -undef
-D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix test.c /tmp/cca06819.cpp
GNU CPP version 1.32
 /usr/public/lib/g++/gcc-c++ /tmp/cca06819.cpp -quiet -dumpbase test.c
-fstrength-reduce -finline-functions -fmemoize-lookups -fsave-memoized
-fchar-charconst -version -o /tmp/cca06819.s
GNU C++ version 1.32.0 (sparc) compiled by GNU C version 1.31.
In function int main ():
test.c:8: [] applied to non-pointer type
test.c:8: [] applied to non-pointer type
test.c:8: invalid lvalue in assignment
test.c:9: [] applied to non-pointer type
test.c:9: invalid type argument of `unary *'
----------------------------------------

This now compiles and executes correctly with the following patch.

Doug

----------------------------------------
*** /usr/src/uci/usr/public/src-g++/cplus-parse.y	Sat Dec 31 13:58:05 1988
--- cplus-parse.y	Sun Jan  1 12:48:16 1989
***************
*** 672,677 ****
--- 672,680 ----
  			else if (TREE_CODE(type) == POINTER_TYPE
  				 || TREE_CODE(type) == ARRAY_TYPE)
  			  $$ = build_array_ref ($1, $3);
+          else if (TREE_CODE (TREE_TYPE ($3)) == POINTER_TYPE
+              || TREE_CODE (TREE_TYPE ($3)) == ARRAY_TYPE)
+ 			  $$ = build_array_ref ($1, $3); 
  			else
  			  error("[] applied to non-pointer type");
  		      }