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]

Re: [c++] warn if NULL is passed through varargs


I think you need a test for this if you are going to
add it to show it works and will work for the future
so we do not have another feature that dies out like
`typedef X=0;'.  Also does this is a good idea for
the c front end too even though c requires NULL to
be a pointer type?

Thanks,
Andrew Pinski

On Tuesday, Oct 8, 2002, at 20:09 US/Pacific, Alexandre Oliva wrote:

Since C++ requires NULL to not be a pointer type, when you pass NULL
through an ellipsis, you probably end up with a type different than
what you expected.  You pretty much have to cast NULL to the right
pointer type in order to guarantee you get the right thing on the
other end.

Arranging for NULL to be an integer constant that evaluates to zero
with an integer type as wide as a pointer would be ideal, but since
there's no guarantee imposed by the C++ Standard that such an integer
type exists, I thought we'd be better off just warning when NULL is
passed as a variable argument without being cast to some other type.

No regressions in mainline on athlon-pc-linux-gnu.  Ok to install?
Hmm...  Perhaps only in the b-i-b?

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* call.c (convert_arg_to_ellipsis): Warn on NULL.

Index: gcc/cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.335
diff -u -p -r1.335 call.c
--- gcc/cp/call.c 21 Sep 2002 12:51:52 -0000 1.335
+++ gcc/cp/call.c 8 Oct 2002 22:24:21 -0000
@@ -4105,6 +4105,9 @@ tree
 convert_arg_to_ellipsis (arg)
      tree arg;
 {
+  if (arg == null_node)
+    warning ("converting NULL to non-pointer type");
+
   if (TREE_CODE (TREE_TYPE (arg)) == REAL_TYPE
       && (TYPE_PRECISION (TREE_TYPE (arg))
 	  < TYPE_PRECISION (double_type_node)))

--
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer






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