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]

c++ int->pointer warnings


This adjusts the C++ front end to act like the C front end in not
warning about size mismatch for constants.  That sort of warning
isn't useful to begin with, and it shows up in real code.  One
example is in libstdc++, but another typical usage is

	p = mmap (...)
	if (p == (caddr_t) -1)
	  error(...)

Also fix some legitimate warnings causing testsuite failures.

Ok?


r~



gcc/
	* c-typeck.c (build_c_cast): Remove dead code.

gcc/cp/
	* typeck.c (build_c_cast): Don't warn integer->pointer size
	mismatch for constants.

gcc/testsuite/
	* g++.old-deja/g++.brendan/code-gen2.C: Cast to size_t, not int.
	* g++.old-deja/g++.mike/warn1.C: Likewise.
	* g++.old-deja/g++.pt/local1.C: Likewise.
	* g++.old-deja/g++.pt/local7.C: Likewise.
	* g++.old-deja/g++.pt/spec16.C: Likewise.

Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-typeck.c,v
retrieving revision 1.63
diff -c -p -d -r1.63 c-typeck.c
*** c-typeck.c	2000/04/10 11:59:46	1.63
--- c-typeck.c	2000/05/05 20:18:59
*************** build_c_cast (type, expr)
*** 3702,3712 ****
        if (TREE_CODE (type) == POINTER_TYPE
  	  && TREE_CODE (otype) == INTEGER_TYPE
  	  && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
- #if 0
- 	  /* Don't warn about converting 0 to pointer,
- 	     provided the 0 was explicit--not cast or made by folding.  */
- 	  && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
- #endif
  	  /* Don't warn about converting any constant.  */
  	  && !TREE_CONSTANT (value))
  	warning ("cast to pointer from integer of different size");
--- 3702,3707 ----
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.282
diff -c -p -d -r1.282 typeck.c
*** cp/typeck.c	2000/05/01 16:51:17	1.282
--- cp/typeck.c	2000/05/05 20:19:00
*************** build_c_cast (type, expr)
*** 5481,5489 ****
    if (TREE_CODE (type) == POINTER_TYPE
        && TREE_CODE (otype) == INTEGER_TYPE
        && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
!       /* Don't warn about converting 0 to pointer,
! 	 provided the 0 was explicit--not cast or made by folding.  */
!       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
      warning ("cast to pointer from integer of different size");
  
    if (TREE_CODE (type) == REFERENCE_TYPE)
--- 5481,5488 ----
    if (TREE_CODE (type) == POINTER_TYPE
        && TREE_CODE (otype) == INTEGER_TYPE
        && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
!       /* Don't warn about converting any constant.  */
!       && !TREE_CONSTANT (value))
      warning ("cast to pointer from integer of different size");
  
    if (TREE_CODE (type) == REFERENCE_TYPE)
Index: testsuite/g++.old-deja/g++.brendan/code-gen2.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.brendan/code-gen2.C,v
retrieving revision 1.3
diff -c -p -d -r1.3 code-gen2.C
*** testsuite/g++.old-deja/g++.brendan/code-gen2.C	2000/01/04 15:52:22	1.3
--- testsuite/g++.old-deja/g++.brendan/code-gen2.C	2000/05/05 20:19:00
*************** int main ()
*** 9,15 ****
  	char buff[40] ;
  	char *tmp = &buff[0];	// also fails for char *tmp = buff;
  
! 	if ((unsigned int) tmp != (unsigned int) &buff[0])
  	  printf ("FAIL\n");
  	else
  	  printf ("PASS\n");
--- 9,15 ----
  	char buff[40] ;
  	char *tmp = &buff[0];	// also fails for char *tmp = buff;
  
! 	if ((__SIZE_TYPE__) tmp != (__SIZE_TYPE__) &buff[0])
  	  printf ("FAIL\n");
  	else
  	  printf ("PASS\n");
Index: testsuite/g++.old-deja/g++.mike/warn1.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.mike/warn1.C,v
retrieving revision 1.2
diff -c -p -d -r1.2 warn1.C
*** testsuite/g++.old-deja/g++.mike/warn1.C	1998/12/16 21:49:30	1.2
--- testsuite/g++.old-deja/g++.mike/warn1.C	2000/05/05 20:19:00
***************
*** 2,9 ****
  // Special g++ Options: -Wall
  
  typedef char * charptr;
  char c[]={'A','B','C','D'};
! int i=int(&c);
  int *pp=&i;
  void foo() { }
  int main()
--- 2,10 ----
  // Special g++ Options: -Wall
  
  typedef char * charptr;
+ typedef __SIZE_TYPE__ size_t;
  char c[]={'A','B','C','D'};
! int i=size_t(&c);
  int *pp=&i;
  void foo() { }
  int main()
Index: testsuite/g++.old-deja/g++.pt/local1.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.pt/local1.C,v
retrieving revision 1.2
diff -c -p -d -r1.2 local1.C
*** testsuite/g++.old-deja/g++.pt/local1.C	1998/12/16 21:57:07	1.2
--- testsuite/g++.old-deja/g++.pt/local1.C	2000/05/05 20:19:00
*************** setback(MEMBER *bp, MEMBER STRUCT::*offs
*** 4,10 ****
          if(!bp) return 0;
          union { int i; MEMBER STRUCT::*of; } u;
          u.of = offset;
!         return (STRUCT *) ((int) bp - u.i);
  }
   
  
--- 4,10 ----
          if(!bp) return 0;
          union { int i; MEMBER STRUCT::*of; } u;
          u.of = offset;
!         return (STRUCT *) ((__SIZE_TYPE__) bp - u.i);
  }
   
  
Index: testsuite/g++.old-deja/g++.pt/local7.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.pt/local7.C,v
retrieving revision 1.1
diff -c -p -d -r1.1 local7.C
*** testsuite/g++.old-deja/g++.pt/local7.C	1999/10/04 09:33:31	1.1
--- testsuite/g++.old-deja/g++.pt/local7.C	2000/05/05 20:19:00
*************** setback(MEMBER *bp, MEMBER STRUCT::*offs
*** 7,13 ****
          if(!bp) return 0;
          union { int i; MEMBER STRUCT::*of; } u;
          u.of = offset;
!         return (STRUCT *) ((int) bp - u.i);
  }
   
  
--- 7,13 ----
          if(!bp) return 0;
          union { int i; MEMBER STRUCT::*of; } u;
          u.of = offset;
!         return (STRUCT *) ((__SIZE_TYPE__) bp - u.i);
  }
   
  
Index: testsuite/g++.old-deja/g++.pt/spec16.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.pt/spec16.C,v
retrieving revision 1.2
diff -c -p -d -r1.2 spec16.C
*** testsuite/g++.old-deja/g++.pt/spec16.C	1998/12/16 21:59:56	1.2
--- testsuite/g++.old-deja/g++.pt/spec16.C	2000/05/05 20:19:00
*************** template<>
*** 17,21 ****
  int
  A<const char*>::foo(const char*const& k)
  {
!         return((int)k);
  }
--- 17,21 ----
  int
  A<const char*>::foo(const char*const& k)
  {
!         return((__SIZE_TYPE__)k);
  }

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