[C++] Patch to diagnostic routines sequence calls.

Gabriel Dos Reis gdr@codesourcery.com
Mon Feb 21 12:22:00 GMT 2000


The patch below was applied.  It complements a previous patch intended
to compress consecutive calss to diagnostic routine.  It also makes the
front-end say 'ISO C++' instead of 'ANSI C++' in various places.
Where possible, we clairify diagnotics.

-- Gaby

2000-02-21  Gabriel Dos Reis  <gdr@codesourcery.com>

	* call.c (build_object_call): Compress consecutive calls to
	cp_error.
	(build_conditional_expr): Say 'ISO C++' not 'ANSI C++'.
	(build_op_delete_call): Adjust message formatting.

	* class.c (check_bases): Compress consecutive calls to
	cp_pedwarn. 
	(finish_struct_anon): Say 'ISO C++'.

	* decl.c (start_decl): Same here.
	(grok_reference_init): Likewise.
	(grokfndecl): Correct message formatting.
	(grokfndecl): Improve diagnostic.
	(check_static_variable_definition): Likewise. Say 'ISO C++'
	(compute_array_index_type): Say 'ISO C++'
	(create_array_type_for_decl): Compress consecutive calls to
	cp_error. 
	(grokdeclarator): Say 'ISO C++'
	(grok_op_properties): Likewise.

	* decl2.c (delete_sanity): Clairify diagnostic.
	(check_member_template): Same here.
	(grok_function_init): Use consistent terminology.

	* expr.c (do_case): Say 'ISO C++'

	* friend.c (do_friend): Compress consecutive calls to warning.

Index: call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.193
diff -p -r1.193 call.c
*** call.c	2000/02/16 23:54:21	1.193
--- call.c	2000/02/21 19:34:06
*************** build_object_call (obj, args)
*** 2556,2563 ****
      {
        /* It's no good looking for an overloaded operator() on a
  	 pointer-to-member-function.  */
!       cp_error ("pointer-to-member function %E cannot be called", obj);
!       cp_error ("without an object; consider using .* or ->*");
        return error_mark_node;
      }
  
--- 2556,2562 ----
      {
        /* It's no good looking for an overloaded operator() on a
  	 pointer-to-member-function.  */
!       cp_error ("pointer-to-member function %E cannot be called without an object; consider using .* or ->*", obj);
        return error_mark_node;
      }
  
*************** build_conditional_expr (arg1, arg2, arg3
*** 2773,2779 ****
    if (!arg2)
      {
        if (pedantic)
! 	pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
        arg1 = arg2 = save_expr (arg1);
      }
  
--- 2772,2778 ----
    if (!arg2)
      {
        if (pedantic)
! 	pedwarn ("ISO C++ forbids omitting the middle term of a ?: expression");
        arg1 = arg2 = save_expr (arg1);
      }
  
*************** build_op_delete_call (code, addr, size, 
*** 3579,3585 ****
    if (flags & LOOKUP_SPECULATIVELY)
      return NULL_TREE;
  
!   cp_error ("no suitable operator delete for `%T'", type);
    return error_mark_node;
  }
  
--- 3578,3584 ----
    if (flags & LOOKUP_SPECULATIVELY)
      return NULL_TREE;
  
!   cp_error ("no suitable `operator delete' for `%T'", type);
    return error_mark_node;
  }
  
Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.261
diff -p -r1.261 class.c
*** class.c	2000/02/21 04:19:11	1.261
--- class.c	2000/02/21 19:34:08
*************** check_bases (t, cant_have_default_ctor_p
*** 1923,1933 ****
  	{
  	  *cant_have_default_ctor_p = 1;
  	  if (! TYPE_HAS_CONSTRUCTOR (t))
! 	    {
! 	      cp_pedwarn ("base `%T' with only non-default constructor",
! 			  basetype);
! 	      cp_pedwarn ("in class without a constructor");
! 	    }
  	}
  
        /* If the base class is not empty or nearly empty, then this
--- 1923,1930 ----
  	{
  	  *cant_have_default_ctor_p = 1;
  	  if (! TYPE_HAS_CONSTRUCTOR (t))
!             cp_pedwarn ("base `%T' with only non-default constructor in class without a constructor",
!                         basetype);
  	}
  
        /* If the base class is not empty or nearly empty, then this
*************** finish_struct_anon (t)
*** 3471,3477 ****
  		continue;
  
  	      if (DECL_NAME (elt) == constructor_name (t))
! 		cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
  			       elt);
  
  	      if (TREE_CODE (elt) != FIELD_DECL)
--- 3468,3474 ----
  		continue;
  
  	      if (DECL_NAME (elt) == constructor_name (t))
! 		cp_pedwarn_at ("ISO C++ forbids member `%D' with same name as enclosing class",
  			       elt);
  
  	      if (TREE_CODE (elt) != FIELD_DECL)
Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.547
diff -p -r1.547 decl.c
*** decl.c	2000/02/20 01:10:49	1.547
--- decl.c	2000/02/21 19:34:10
*************** start_decl (declarator, declspecs, initi
*** 6789,6795 ****
  	    {
  	      if (DECL_CONTEXT (field) != context)
  		{
! 		  cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'",
  			      DECL_CONTEXT (field), DECL_NAME (decl),
  			      context, DECL_NAME (decl));
  		  DECL_CONTEXT (decl) = DECL_CONTEXT (field);
--- 6789,6795 ----
  	    {
  	      if (DECL_CONTEXT (field) != context)
  		{
! 		  cp_pedwarn ("ISO C++ does not permit `%T::%D' to be defined as `%T::%D'",
  			      DECL_CONTEXT (field), DECL_NAME (decl),
  			      context, DECL_NAME (decl));
  		  DECL_CONTEXT (decl) = DECL_CONTEXT (field);
*************** grok_reference_init (decl, type, init)
*** 6959,6965 ****
  
    if (TREE_CODE (init) == CONSTRUCTOR)
      {
!       cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
        return;
      }
  
--- 6959,6965 ----
  
    if (TREE_CODE (init) == CONSTRUCTOR)
      {
!       cp_error ("ISO C++ forbids use of initializer list to initialize reference `%D'", decl);
        return;
      }
  
*************** grokfndecl (ctype, type, declarator, ori
*** 8449,8459 ****
    if (ctype == NULL_TREE && DECL_MAIN_P (decl))
      {
        if (processing_template_decl)
! 	error ("cannot declare `main' to be a template");
        if (inlinep)
! 	error ("cannot declare `main' to be inline");
        else if (! publicp)
! 	error ("cannot declare `main' to be static");
        inlinep = 0;
        publicp = 1;
      }
--- 8449,8459 ----
    if (ctype == NULL_TREE && DECL_MAIN_P (decl))
      {
        if (processing_template_decl)
! 	error ("cannot declare `::main' to be a template");
        if (inlinep)
! 	error ("cannot declare `::main' to be inline");
        else if (! publicp)
! 	error ("cannot declare `::main' to be static");
        inlinep = 0;
        publicp = 1;
      }
*************** grokfndecl (ctype, type, declarator, ori
*** 8532,8538 ****
  	  if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  	    {
  	      /* Something like `template <class T> friend void f<T>()'.  */
! 	      cp_error ("template-id `%D' in declaration of primary template",
  			orig_declarator);
  	      return NULL_TREE;
  	    }
--- 8532,8538 ----
  	  if (PROCESSING_REAL_TEMPLATE_DECL_P ())
  	    {
  	      /* Something like `template <class T> friend void f<T>()'.  */
! 	      cp_error ("invalid use of template-id `%D' in declaration of primary template",
  			orig_declarator);
  	      return NULL_TREE;
  	    }
*************** check_static_variable_definition (decl, 
*** 8870,8876 ****
       required.  */
    if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
      {
!       cp_error ("in-class initialization of static data member of non-integral type `%T'",
  		type);
        /* If we just return the declaration, crashes will sometimes
  	 occur.  We therefore return void_type_node, as if this was a
--- 8870,8876 ----
       required.  */
    if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
      {
!       cp_error ("invalid in-class initialization of static data member of non-integral type `%T'",
  		type);
        /* If we just return the declaration, crashes will sometimes
  	 occur.  We therefore return void_type_node, as if this was a
*************** check_static_variable_definition (decl, 
*** 8879,8888 ****
        return 1;
      }
    else if (!CP_TYPE_CONST_P (type))
!     cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  	      decl);
    else if (pedantic && !INTEGRAL_TYPE_P (type))
!     cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type);
  
    return 0;
  }
--- 8879,8888 ----
        return 1;
      }
    else if (!CP_TYPE_CONST_P (type))
!     cp_error ("ISO C++ forbids in-class initialization of non-const static member `%D'",
  	      decl);
    else if (pedantic && !INTEGRAL_TYPE_P (type))
!     cp_pedwarn ("ISO C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type);
  
    return 0;
  }
*************** compute_array_index_type (name, size)
*** 8966,8974 ****
        else if (integer_zerop (size) && pedantic && !in_system_header)
  	{
  	  if (name)
! 	    cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", name);
  	  else
! 	    cp_pedwarn ("ANSI C++ forbids zero-size array");
  	}
      }
  
--- 8966,8974 ----
        else if (integer_zerop (size) && pedantic && !in_system_header)
  	{
  	  if (name)
! 	    cp_pedwarn ("ISO C++ forbids zero-size array `%D'", name);
  	  else
! 	    cp_pedwarn ("ISO C++ forbids zero-size array");
  	}
      }
  
*************** compute_array_index_type (name, size)
*** 8987,8996 ****
        if (pedantic)
  	{
  	  if (name)
! 	    cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
  			name);
  	  else
! 	    cp_pedwarn ("ANSI C++ forbids variable-size array");
  	}
  
        /* Create a variable-sized array index type.  */
--- 8987,8996 ----
        if (pedantic)
  	{
  	  if (name)
! 	    cp_pedwarn ("ISO C++ forbids variable-size array `%D'",
  			name);
  	  else
! 	    cp_pedwarn ("ISO C++ forbids variable-size array");
  	}
  
        /* Create a variable-sized array index type.  */
*************** create_array_type_for_decl (name, type, 
*** 9073,9081 ****
       can be omitted only for the first member of the sequence.  */
    if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
      {
!       cp_error ("declaration of `%D' as multidimensional array",
  		name);
-       cp_error ("must have bounds for all dimensions except the first");
  
        return error_mark_node;
      }
--- 9073,9080 ----
       can be omitted only for the first member of the sequence.  */
    if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
      {
!       cp_error ("declaration of `%D' as multidimensional array must have bounds for all dimensions except the first",
  		name);
  
        return error_mark_node;
      }
*************** grokdeclarator (declarator, declspecs, d
*** 9604,9610 ****
  		  if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
  		    {
  		      if (pedantic && ! in_system_header && warn_long_long)
! 			pedwarn ("ANSI C++ does not support `long long'");
  		      if (longlong)
  			error ("`long long long' is too long for GCC");
  		      else
--- 9603,9609 ----
  		  if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
  		    {
  		      if (pedantic && ! in_system_header && warn_long_long)
! 			pedwarn ("ISO C++ does not support `long long'");
  		      if (longlong)
  			error ("`long long long' is too long for GCC");
  		      else
*************** grokdeclarator (declarator, declspecs, d
*** 9694,9703 ****
  	  if (in_system_header || flag_ms_extensions)
  	    /* Allow it, sigh.  */;
  	  else if (pedantic || ! is_main)
! 	    cp_pedwarn ("ANSI C++ forbids declaration of `%s' with no type",
  			name);
  	  else if (warn_return_type)
! 	    cp_warning ("ANSI C++ forbids declaration of `%s' with no type",
  			name);
  
  	  type = integer_type_node;
--- 9693,9702 ----
  	  if (in_system_header || flag_ms_extensions)
  	    /* Allow it, sigh.  */;
  	  else if (pedantic || ! is_main)
! 	    cp_pedwarn ("ISO C++ forbids declaration of `%s' with no type",
  			name);
  	  else if (warn_return_type)
! 	    cp_warning ("ISO C++ forbids declaration of `%s' with no type",
  			name);
  
  	  type = integer_type_node;
*************** grokdeclarator (declarator, declspecs, d
*** 10655,10661 ****
        if (decl_context == FIELD)
  	{
  	  if (declarator == constructor_name (current_class_type))
! 	    cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class",
  			declarator);
  	  decl = build_lang_decl (TYPE_DECL, declarator, type);
  	}
--- 10654,10660 ----
        if (decl_context == FIELD)
  	{
  	  if (declarator == constructor_name (current_class_type))
! 	    cp_pedwarn ("ISO C++ forbids nested type `%D' with same name as enclosing class",
  			declarator);
  	  decl = build_lang_decl (TYPE_DECL, declarator, type);
  	}
*************** grokdeclarator (declarator, declspecs, d
*** 10726,10732 ****
  	  if (ctype == NULL_TREE)
  	    {
  	      if (TREE_CODE (type) != METHOD_TYPE)
! 		cp_error_at ("invalid type qualifier for non-method type", decl);
  	      else
  		ctype = TYPE_METHOD_BASETYPE (type);
  	    }
--- 10725,10731 ----
  	  if (ctype == NULL_TREE)
  	    {
  	      if (TREE_CODE (type) != METHOD_TYPE)
! 		cp_error_at ("invalid type qualifier for non-member function type", decl);
  	      else
  		ctype = TYPE_METHOD_BASETYPE (type);
  	    }
*************** grokdeclarator (declarator, declspecs, d
*** 11042,11048 ****
  	  {
  	    if (friendp)
  	      {
! 		error ("`%s' is neither function nor method; cannot be declared friend",
  		       IDENTIFIER_POINTER (declarator));
  		friendp = 0;
  	      }
--- 11041,11047 ----
  	  {
  	    if (friendp)
  	      {
! 		error ("`%s' is neither function nor member function; cannot be declared friend",
  		       IDENTIFIER_POINTER (declarator));
  		friendp = 0;
  	      }
*************** grokdeclarator (declarator, declspecs, d
*** 11125,11131 ****
  		   allow non-static data members here, because C does
  		   and /usr/include/netinet/in.h uses that.  */
  		&& (staticp || ! in_system_header))
! 	      cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class",
  			  declarator);
  
  	    if (staticp)
--- 11124,11130 ----
  		   allow non-static data members here, because C does
  		   and /usr/include/netinet/in.h uses that.  */
  		&& (staticp || ! in_system_header))
! 	      cp_pedwarn ("ISO C++ forbids data member `%D' with same name as enclosing class",
  			  declarator);
  
  	    if (staticp)
*************** grok_op_properties (decl, virtualp, frie
*** 12004,12010 ****
        else if (name == ansi_opname[(int) COND_EXPR])
  	{
  	  /* 13.4.0.3 */
! 	  cp_error ("ANSI C++ prohibits overloading operator ?:");
  	}
        else if (ambi_op_p (name))
  	{
--- 12003,12009 ----
        else if (name == ansi_opname[(int) COND_EXPR])
  	{
  	  /* 13.4.0.3 */
! 	  cp_error ("ISO C++ prohibits overloading operator ?:");
  	}
        else if (ambi_op_p (name))
  	{
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.309
diff -p -r1.309 decl2.c
*** decl2.c	2000/02/18 06:00:36	1.309
--- decl2.c	2000/02/21 19:34:11
*************** delete_sanity (exp, size, doing_vec, use
*** 1187,1193 ****
    /* You can't delete functions.  */
    if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
      {
!       error ("cannot delete a function");
        return error_mark_node;
      }
  
--- 1187,1193 ----
    /* You can't delete functions.  */
    if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
      {
!       error ("cannot delete a function.  Only pointer-to-objects are valid arguments to `delete'");
        return error_mark_node;
      }
  
*************** check_member_template (tmpl)
*** 1245,1251 ****
  	/* 14.5.2.2 [temp.mem]
  	   
  	   A local class shall not have member templates. */
! 	cp_error ("declaration of member template `%#D' in local class",
  		  decl);
        
        if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
--- 1245,1251 ----
  	/* 14.5.2.2 [temp.mem]
  	   
  	   A local class shall not have member templates. */
! 	cp_error ("invalid declaration of member template `%#D' in local class",
  		  decl);
        
        if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
*************** grok_function_init (decl, init)
*** 1862,1868 ****
  #if 0
    /* We'll check for this in finish_struct_1.  */
    else if (DECL_VINDEX (decl) == NULL_TREE)
!     cp_error ("initializer specified for non-virtual method `%D'", decl);
  #endif
    else if (integer_zerop (init))
      {
--- 1862,1868 ----
  #if 0
    /* We'll check for this in finish_struct_1.  */
    else if (DECL_VINDEX (decl) == NULL_TREE)
!     cp_error ("initializer specified for non-virtual member function `%D'", decl);
  #endif
    else if (integer_zerop (init))
      {
Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/expr.c,v
retrieving revision 1.40
diff -p -r1.40 expr.c
*** expr.c	2000/01/26 20:51:34	1.40
--- expr.c	2000/02/21 19:34:11
*************** do_case (start, end)
*** 290,296 ****
      error ("pointers are not permitted as case values");
  
    if (end && pedantic)
!     pedwarn ("ANSI C++ forbids range expressions in switch statement");
  
    if (start)
      value1 = check_cp_case_value (start);
--- 290,296 ----
      error ("pointers are not permitted as case values");
  
    if (end && pedantic)
!     pedwarn ("ISO C++ forbids range expressions in switch statement");
  
    if (start)
      value1 = check_cp_case_value (start);
Index: friend.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/friend.c,v
retrieving revision 1.53
diff -p -r1.53 friend.c
*** friend.c	2000/02/16 23:54:22	1.53
--- friend.c	2000/02/21 19:34:11
*************** do_friend (ctype, declarator, decl, parm
*** 410,419 ****
  	      warning ("  declares a non-template function");
  	      if (! explained)
  		{
! 		  warning ("  (if this is not what you intended, make sure");
! 		  warning ("  the function template has already been declared,");
! 		  warning ("  and add <> after the function name here)");
!  		  warning ("  -Wno-non-template-friend disables this warning.");
  		  explained = 1;
  		}
  	    }
--- 410,416 ----
  	      warning ("  declares a non-template function");
  	      if (! explained)
  		{
! 		  warning ("  (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning.");
  		  explained = 1;
  		}
  	    }






More information about the Gcc-patches mailing list