This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcj/48: Compiler fails to catch constructor problem


The following reply was made to PR gcj/48; it has been noted by GNATS.

From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: green@cygnus.com
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/48: Compiler fails to catch constructor problem
Date: Fri, 29 Oct 1999 08:51:34 -0700 (PDT)

 green@cygnus.com writes:
 
 > The compiler fails to catch the use of `this' in a 
 > constructor before calling the superclass constructor.
 
 I have a patch for that, see below. With that patch, I get several
 failures compiling libjava:
 
 --
 java/io/InputStreamReader.java:47: Can't reference `this' before the superclass constructor has been called.
     super((this.in = (in instanceof BufferedInputStream
            ^
 1 error
 
 java/io/OutputStreamWriter.java:35: Can't reference `this' before the superclass constructor has been called.
     super((this.out = (out instanceof BufferedOutputStream
            ^
 1 error
 
 java/io/PrintStream.java:241: Can't reference `this' before the superclass constructor has been called.
     super ((this.out = (out instanceof BufferedOutputStream
             ^
 1 error
 --
 
 If someone can confirm these errors, I'll update PR #50 with the
 mention of `InputStreamReader'.
 
 ./A
 
 Index: parse.y
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
 retrieving revision 1.114
 diff -u -p -r1.114 parse.y
 --- parse.y	1999/10/22 06:06:47	1.114
 +++ parse.y	1999/10/29 15:29:12
 @@ -6716,6 +6716,12 @@ resolve_qualified_expression_name (wfl, 
  		(wfl, "Keyword `this' used outside allowed context");
  	      return 1;
  	    }
 +	  if (ctxp->explicit_constructor_p)
 +	    {
 +	      parse_error_context (wfl, "Can't reference `this' before the "
 +				   "superclass constructor has been called");
 +	      return 1;
 +	    }
  	  /* We have to generate code for intermediate acess */
  	  *where_found = decl = current_this;
  	  *type_found = type = QUAL_DECL_TYPE (decl);
 @@ -8723,7 +8729,7 @@ complete_function_arguments (node)
    int flag = 0;
    tree cn;
  
 -  ctxp->explicit_constructor_p += (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
 +  ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
    for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
      {
        tree wfl = TREE_VALUE (cn), parm, temp;
 @@ -8743,7 +8749,7 @@ complete_function_arguments (node)
  
        TREE_VALUE (cn) = parm;
      }
 -  ctxp->explicit_constructor_p -= (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
 +  ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
    return flag;
  }
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]