This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa] handle integer downsizing correctly in C++ overloading
- From: David Carlton <carlton at math dot stanford dot edu>
- To: gdb-patches at sources dot redhat dot com
- Cc: Daniel Jacobowitz <drow at mvista dot com>
- Date: 31 Jan 2003 11:57:29 -0800
- Subject: [rfa] handle integer downsizing correctly in C++ overloading
GDB currently won't let you do narrowing integer conversions when
calling an overloaded C++ function: compile this,
int overloadChar(char c)
{
return 29;
}
int main()
{
overloadChar(1);
}
break on main, and try to print overloadChar(1).
The problem is that gdbtypes.h defines both INTEGER_COERCION_BADNESS
and INTEGER_CONVERSION_BADNESS. The former is unacceptably bad; the
latter isn't preferred, but isn't acceptable. And in all (or almost
all) cases, the type comparison functions use INTEGER_COERCION_BADNESS
when doing narrowing integer comparisons, when they should use
INTEGER_CONVERSION_BADNESS.
In fact, INTEGER_COERCION_BADNESS shouldn't exist: there's no such
thing as an unacceptably bad integer conversion. So this patch
changes all uses of INTEGER_COERCION_BADNESS to refer to
INTEGER_CONVERSION_BADNESS, deletes INTEGER_COERCION_BADNESS, and also
deletes FLOAT_COERCION_BADNESS (which is similarly unnecessary but
which is already correctly unused). And there's a testsuite patch
included to catch this as well.
Tested on i686-pc-linux-gnu/GCC3.1/DWARF-2; OK to commit?
David Carlton
carlton@math.stanford.edu
2003-01-31 David Carlton <carlton@math.stanford.edu>
* gdbtypes.h: Delete INTEGER_COERCION_BADNESS,
FLOAT_COERCION_BADNESS.
* gdbtypes.c (rank_one_type): Replace all uses of
INTEGER_COERCION_BADNESS by INTEGER_CONVERSION_BADNESS.
2003-01-31 David Carlton <carlton@math.stanford.edu>
* gdb.c++/overload.exp: Test intToChar(1).
* gdb.c++/overload.cc (intToChar): New.
(main): Call intToChar.
Index: gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.42
diff -u -p -r1.42 gdbtypes.h
--- gdbtypes.h 19 Jan 2003 04:06:45 -0000 1.42
+++ gdbtypes.h 31 Jan 2003 19:26:04 -0000
@@ -1211,10 +1211,6 @@ extern int count_virtual_fns (struct typ
#define TOO_FEW_PARAMS_BADNESS 100
/* Badness if no conversion among types */
#define INCOMPATIBLE_TYPE_BADNESS 100
-/* Badness of coercing large integer to smaller size */
-#define INTEGER_COERCION_BADNESS 100
-/* Badness of coercing large floating type to smaller size */
-#define FLOAT_COERCION_BADNESS 100
/* Badness of integral promotion */
#define INTEGER_PROMOTION_BADNESS 1
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.69
diff -u -p -r1.69 gdbtypes.c
--- gdbtypes.c 17 Jan 2003 19:12:18 -0000 1.69
+++ gdbtypes.c 31 Jan 2003 19:28:36 -0000
@@ -2591,7 +2591,7 @@ rank_one_type (struct type *parm, struct
if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
return 0;
else
- return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
+ return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
}
else if (TYPE_UNSIGNED (parm))
{
@@ -2604,13 +2604,13 @@ rank_one_type (struct type *parm, struct
&& integer_types_same_name_p (TYPE_NAME (parm), "long"))
return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
else
- return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
+ return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
}
else
{
if (integer_types_same_name_p (TYPE_NAME (arg), "long")
&& integer_types_same_name_p (TYPE_NAME (parm), "int"))
- return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
+ return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
else
return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
}
@@ -2623,15 +2623,15 @@ rank_one_type (struct type *parm, struct
&& integer_types_same_name_p (TYPE_NAME (parm), "long"))
return INTEGER_PROMOTION_BADNESS;
else
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
}
else
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
}
else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
return INTEGER_PROMOTION_BADNESS;
else
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_ENUM:
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
@@ -2653,7 +2653,7 @@ rank_one_type (struct type *parm, struct
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
case TYPE_CODE_ENUM:
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_FLT:
return INT_FLOAT_CONVERSION_BADNESS;
default:
@@ -2666,12 +2666,12 @@ rank_one_type (struct type *parm, struct
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
case TYPE_CODE_ENUM:
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_FLT:
return INT_FLOAT_CONVERSION_BADNESS;
case TYPE_CODE_INT:
if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
return INTEGER_PROMOTION_BADNESS;
/* >>> !! else fall through !! <<< */
@@ -2683,7 +2683,7 @@ rank_one_type (struct type *parm, struct
if (TYPE_NOSIGN (arg))
return 0;
else
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
}
else if (TYPE_UNSIGNED (parm))
{
@@ -2695,7 +2695,7 @@ rank_one_type (struct type *parm, struct
else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
return 0;
else
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
default:
return INCOMPATIBLE_TYPE_BADNESS;
}
@@ -2708,7 +2708,7 @@ rank_one_type (struct type *parm, struct
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
case TYPE_CODE_ENUM:
- return INTEGER_COERCION_BADNESS;
+ return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_FLT:
return INT_FLOAT_CONVERSION_BADNESS;
default: