This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: have warning take option code


this is part of a larger patch sitting in my local tree.  I'll let
Lee Millward apply his, before doing anything further.
Bootstrapped and regtested on an i686-pc-linux-gnu.

-- Gaby

2006-01-28  Gabriel Dos Reis  <gdr@cs.tamu.edu>

	* class.c (check_bases): Likewise.
	(maybe_warn_about_overly_private_class): Likewise.
	(check_field_decls): Likewise.
	(layout_empty_base): Likewise.
	(layout_virtual_bases): Likewise.
	(layout_class_type): Likewise.

	* call.c (joust): Pass option code to warning.  Use inform for
	explanation. 

*** gcc/cp/call.c	(revision 110343)
--- gcc/cp/call.c	(local)
*************** joust (struct z_candidate *cand1, struct
*** 6029,6037 ****
  
  	      if (warn)
  		{
! 		  warning (0, "passing %qT chooses %qT over %qT",
! 			      type, type1, type2);
! 		  warning (0, "  in call to %qD", w->fn);
  		}
  	      else
  		add_warning (w, l);
--- 6029,6037 ----
  
  	      if (warn)
  		{
! 		  warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
!                            type, type1, type2);
! 		  warning (OPT_Wsign_promo, "  in call to %qD", w->fn);
  		}
  	      else
  		add_warning (w, l);
*************** joust (struct z_candidate *cand1, struct
*** 6088,6097 ****
  	  tree source = source_type (w->convs[0]);
  	  if (! DECL_CONSTRUCTOR_P (w->fn))
  	    source = TREE_TYPE (source);
! 	  warning (0, "choosing %qD over %qD", w->fn, l->fn);
! 	  warning (0, "  for conversion from %qT to %qT",
  		   source, w->second_conv->type);
! 	  warning (0, "  because conversion sequence for the argument is better");
  	}
        else
  	add_warning (w, l);
--- 6088,6097 ----
  	  tree source = source_type (w->convs[0]);
  	  if (! DECL_CONSTRUCTOR_P (w->fn))
  	    source = TREE_TYPE (source);
! 	  warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn);
! 	  warning (OPT_Wconversion, "  for conversion from %qT to %qT",
  		   source, w->second_conv->type);
! 	  inform ("  because conversion sequence for the argument is better");
  	}
        else
  	add_warning (w, l);
*** gcc/cp/class.c	(revision 110343)
--- gcc/cp/class.c	(local)
*************** check_bases (tree t,
*** 1227,1234 ****
        /* Effective C++ rule 14.  We only need to check TYPE_POLYMORPHIC_P
  	 here because the case of virtual functions but non-virtual
  	 dtor is handled in finish_struct_1.  */
!       if (warn_ecpp && ! TYPE_POLYMORPHIC_P (basetype))
! 	warning (0, "base class %q#T has a non-virtual destructor", basetype);
  
        /* If the base class doesn't have copy constructors or
  	 assignment operators that take const references, then the
--- 1227,1235 ----
        /* Effective C++ rule 14.  We only need to check TYPE_POLYMORPHIC_P
  	 here because the case of virtual functions but non-virtual
  	 dtor is handled in finish_struct_1.  */
!       if (!TYPE_POLYMORPHIC_P (basetype))
! 	warning (OPT_Weffc__,
!                  "base class %q#T has a non-virtual destructor", basetype);
  
        /* If the base class doesn't have copy constructors or
  	 assignment operators that take const references, then the
*************** maybe_warn_about_overly_private_class (t
*** 1542,1548 ****
  	  }
        if (!has_nonprivate_method)
  	{
! 	  warning (0, "all member functions in class %qT are private", t);
  	  return;
  	}
      }
--- 1543,1550 ----
  	  }
        if (!has_nonprivate_method)
  	{
! 	  warning (OPT_Wctor_dtor_privacy,
!                    "all member functions in class %qT are private", t);
  	  return;
  	}
      }
*************** maybe_warn_about_overly_private_class (t
*** 1553,1559 ****
    fn = CLASSTYPE_DESTRUCTORS (t);
    if (fn && TREE_PRIVATE (fn))
      {
!       warning (0, "%q#T only defines a private destructor and has no friends",
  	       t);
        return;
      }
--- 1555,1562 ----
    fn = CLASSTYPE_DESTRUCTORS (t);
    if (fn && TREE_PRIVATE (fn))
      {
!       warning (OPT_Wctor_dtor_privacy,
!                "%q#T only defines a private destructor and has no friends",
  	       t);
        return;
      }
*************** maybe_warn_about_overly_private_class (t
*** 1596,1602 ****
  
        if (nonprivate_ctor == 0)
  	{
! 	  warning (0, "%q#T only defines private constructors and has no friends",
  		   t);
  	  return;
  	}
--- 1599,1606 ----
  
        if (nonprivate_ctor == 0)
  	{
! 	  warning (OPT_Wctor_dtor_privacy,
!                    "%q#T only defines private constructors and has no friends",
  		   t);
  	  return;
  	}
*************** check_field_decls (tree t, tree *access_
*** 3032,3043 ****
  
        if (! TYPE_HAS_INIT_REF (t))
  	{
! 	  warning (0, "  but does not override %<%T(const %T&)%>", t, t);
! 	  if (! TYPE_HAS_ASSIGN_REF (t))
! 	    warning (0, "  or %<operator=(const %T&)%>", t);
  	}
        else if (! TYPE_HAS_ASSIGN_REF (t))
! 	warning (0, "  but does not override %<operator=(const %T&)%>", t);
      }
  
  
--- 3036,3049 ----
  
        if (! TYPE_HAS_INIT_REF (t))
  	{
! 	  warning (OPT_Weffc__,
!                    "  but does not override %<%T(const %T&)%>", t, t);
! 	  if (!TYPE_HAS_ASSIGN_REF (t))
! 	    warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
  	}
        else if (! TYPE_HAS_ASSIGN_REF (t))
! 	warning (OPT_Weffc__,
!                  "  but does not override %<operator=(const %T&)%>", t);
      }
  
  
*************** layout_empty_base (tree binfo, tree eoc,
*** 3492,3499 ****
        if (abi_version_at_least (2))
  	propagate_binfo_offsets
  	  (binfo, size_diffop (size_zero_node, BINFO_OFFSET (binfo)));
!       else if (warn_abi)
! 	warning (0, "offset of empty base %qT may not be ABI-compliant and may"
  		 "change in a future version of GCC",
  		 BINFO_TYPE (binfo));
      }
--- 3498,3506 ----
        if (abi_version_at_least (2))
  	propagate_binfo_offsets
  	  (binfo, size_diffop (size_zero_node, BINFO_OFFSET (binfo)));
!       else
! 	warning (OPT_Wabi,
!                  "offset of empty base %qT may not be ABI-compliant and may"
  		 "change in a future version of GCC",
  		 BINFO_TYPE (binfo));
      }
*************** build_base_field (record_layout_info rli
*** 3604,3611 ****
  	    {
  	      if (abi_version_at_least (2))
  		CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
! 	      else if (warn_abi)
! 		warning (0, "class %qT will be considered nearly empty in a "
  			 "future version of GCC", t);
  	    }
  	}
--- 3611,3619 ----
  	    {
  	      if (abi_version_at_least (2))
  		CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
! 	      else
! 		warning (OPT_Wabi,
!                          "class %qT will be considered nearly empty in a "
  			 "future version of GCC", t);
  	    }
  	}
*************** layout_virtual_bases (record_layout_info
*** 4349,4355 ****
  					 CLASSTYPE_ALIGN (basetype)),
  			       bitsize_unit_node),
  		   BINFO_OFFSET (vbase))))
! 	    warning (0, "offset of virtual base %qT is not ABI-compliant and "
  		     "may change in a future version of GCC",
  		     basetype);
  
--- 4357,4364 ----
  					 CLASSTYPE_ALIGN (basetype)),
  			       bitsize_unit_node),
  		   BINFO_OFFSET (vbase))))
! 	    warning (OPT_Wabi,
!                      "offset of virtual base %qT is not ABI-compliant and "
  		     "may change in a future version of GCC",
  		     basetype);
  
*************** layout_class_type (tree t, tree *virtual
*** 4636,4643 ****
  		padding = DECL_SIZE (field);
  	      else
  		{
! 		  if (warn_abi && TREE_CODE (t) == UNION_TYPE)
! 		    warning (0, "size assigned to %qT may not be "
  			     "ABI-compliant and may change in a future "
  			     "version of GCC",
  			     t);
--- 4645,4652 ----
  		padding = DECL_SIZE (field);
  	      else
  		{
! 		  if (TREE_CODE (t) == UNION_TYPE)
! 		    warning (OPT_Wabi, "size assigned to %qT may not be "
  			     "ABI-compliant and may change in a future "
  			     "version of GCC",
  			     t);
*************** layout_class_type (tree t, tree *virtual
*** 4676,4682 ****
  		   && DECL_MODE (field) != TYPE_MODE (type))
  	    /* Versions of G++ before G++ 3.4 did not reset the
  	       DECL_MODE.  */
! 	    warning (0, "the offset of %qD may not be ABI-compliant and may "
  		     "change in a future version of GCC", field);
  	}
        else
--- 4685,4692 ----
  		   && DECL_MODE (field) != TYPE_MODE (type))
  	    /* Versions of G++ before G++ 3.4 did not reset the
  	       DECL_MODE.  */
! 	    warning (OPT_Wabi,
!                      "the offset of %qD may not be ABI-compliant and may "
  		     "change in a future version of GCC", field);
  	}
        else
*************** layout_class_type (tree t, tree *virtual
*** 4704,4710 ****
  	  && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
  					 DECL_FIELD_BIT_OFFSET (field),
  					 bitsize_unit_node)))
! 	warning (0, "offset of %q+D is not ABI-compliant and may "
  		 "change in a future version of GCC", field);
  
        /* G++ used to use DECL_FIELD_OFFSET as if it were the byte
--- 4714,4720 ----
  	  && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
  					 DECL_FIELD_BIT_OFFSET (field),
  					 bitsize_unit_node)))
! 	warning (OPT_Wabi, "offset of %q+D is not ABI-compliant and may "
  		 "change in a future version of GCC", field);
  
        /* G++ used to use DECL_FIELD_OFFSET as if it were the byte
*************** layout_class_type (tree t, tree *virtual
*** 4713,4719 ****
  	  && !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
  				  byte_position (field))
  	  && contains_empty_class_p (TREE_TYPE (field)))
! 	warning (0, "%q+D contains empty classes which may cause base "
  		 "classes to be placed at different locations in a "
  		 "future version of GCC", field);
  
--- 4723,4729 ----
  	  && !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
  				  byte_position (field))
  	  && contains_empty_class_p (TREE_TYPE (field)))
! 	warning (OPT_Wabi, "%q+D contains empty classes which may cause base "
  		 "classes to be placed at different locations in a "
  		 "future version of GCC", field);
  
*************** layout_class_type (tree t, tree *virtual
*** 4772,4778 ****
  	  TYPE_SIZE (base_t) = bitsize_zero_node;
  	  TYPE_SIZE_UNIT (base_t) = size_zero_node;
  	  if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
! 	    warning (0, "layout of classes derived from empty class %qT "
  		     "may change in a future version of GCC",
  		     t);
  	}
--- 4782,4789 ----
  	  TYPE_SIZE (base_t) = bitsize_zero_node;
  	  TYPE_SIZE_UNIT (base_t) = size_zero_node;
  	  if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
! 	    warning (OPT_Wabi,
!                      "layout of classes derived from empty class %qT "
  		     "may change in a future version of GCC",
  		     t);
  	}


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