From: eggert@twinsun.COM (Paul Eggert)
Subject: GCC 2.2.2 outputs confusing diagnostics for statics with unknown size
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 11 Aug 1992 19:53:11 GMT

For the erroneous program

	static struct s x;
	struct s y;

GCC 2.2.2 (Sparc, SunOS 4.1.2) outputs the following diagnostics:

	t.c:1: storage size of `x' isn't known
	t.c:1: storage size of static var `x' isn't known
	t.c:2: storage size of static var `y' isn't known

These messages are confusing for the following reasons.

	1.  There are two redundant messages for the error in line 1.
	2.  In line 2, `y' is reported to be static, even though it
	was not declared `static'.
	3.  In the first line, `x' is not reported to be a var, as it
	is in the other two lines.

Here is a patch.

Tue Aug 11 19:43:13 1992  Paul Eggert  (eggert@twinsun.com)

	* c-decl.c (finish_decl): Avoid cascading messages for tentative
	definitions with incomplete types.  Normalize diagnostic wording.
	* varasm.c (assemble_variable): Clarify diagnostic.

===================================================================
RCS file: c-decl.c,v
retrieving revision 2.2.2.2
diff -c -r2.2.2.2 c-decl.c
*** c-decl.c	1992/07/25 00:13:45	2.2.2.2
--- c-decl.c	1992/08/11 19:43:13
***************
*** 3026,3045 ****
  
    if (TREE_CODE (decl) == VAR_DECL)
      {
!       if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
  	{
! 	  /* A static variable with an incomplete type:
! 	     that is an error if it is initialized or `static'.
! 	     Otherwise, let it through, but if it is not `extern'
! 	     then it may cause an error message later.  */
! 	  if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
! 	    error_with_decl (decl, "storage size of `%s' isn't known");
! 	}
!       else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
! 	{
! 	  /* An automatic variable with an incomplete type:
! 	     that is an error.  */
! 	  error_with_decl (decl, "storage size of `%s' isn't known");
  	  TREE_TYPE (decl) = error_mark_node;
  	}
  
--- 3026,3045 ----
  
    if (TREE_CODE (decl) == VAR_DECL)
      {
!       if (DECL_SIZE (decl) == 0
! 	  && (TREE_STATIC (decl)
! 	      ?
! 		/* A static variable with an incomplete type
! 		   is an error if it is initialized or `static'.
! 		   Otherwise, let it through, but if it is not `extern'
! 		   then it may cause an error message later.  */
! 		!TREE_PUBLIC (decl) || DECL_INITIAL (decl)
! 	      :
! 		/* An automatic variable with an incomplete type
! 		   is an error.  */
! 		!TREE_EXTERNAL (decl)))
  	{
! 	  error_with_decl (decl, "storage size of var `%s' isn't known");
  	  TREE_TYPE (decl) = error_mark_node;
  	}
  
***************
*** 3046,3052 ****
        if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
  	  && DECL_SIZE (decl) != 0
  	  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
! 	error_with_decl (decl, "storage size of `%s' isn't constant");
      }
  
    /* Output the assembler code and/or RTL code for variables and functions,
--- 3046,3052 ----
        if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
  	  && DECL_SIZE (decl) != 0
  	  && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
! 	error_with_decl (decl, "storage size of var `%s' isn't constant");
      }
  
    /* Output the assembler code and/or RTL code for variables and functions,
===================================================================
RCS file: RCS/varasm.c,v
retrieving revision 2.2
diff -c -r2.2 varasm.c
*** varasm.c	1992/05/21 18:24:40	2.2
--- varasm.c	1992/08/11 19:43:13
***************
*** 701,707 ****
      {
        error_with_file_and_line (DECL_SOURCE_FILE (decl),
  				DECL_SOURCE_LINE (decl),
! 				"storage size of static var `%s' isn't known",
  				IDENTIFIER_POINTER (DECL_NAME (decl)));
        return;
      }
--- 701,707 ----
      {
        error_with_file_and_line (DECL_SOURCE_FILE (decl),
  				DECL_SOURCE_LINE (decl),
! 				"storage size of var `%s' isn't known",
  				IDENTIFIER_POINTER (DECL_NAME (decl)));
        return;
      }

Newsgroups: gnu.gcc.bug