From: David Carlton <carlton@math.stanford.edu>
To: gdb-patches@sources.redhat.com
Cc: Daniel Jacobowitz <drow@mvista.com>
Subject: [rfa] handle integer downsizing correctly in C++ overloading
Date: Fri, 31 Jan 2003 19:57:00 -0000 [thread overview]
Message-ID: <ro1fzr9gkie.fsf@jackfruit.Stanford.EDU> (raw)
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:
next reply other threads:[~2003-01-31 19:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-31 19:57 David Carlton [this message]
2003-01-31 20:04 ` David Carlton
2003-02-04 19:10 ` Daniel Jacobowitz
2003-02-04 21:23 ` David Carlton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ro1fzr9gkie.fsf@jackfruit.Stanford.EDU \
--to=carlton@math.stanford.edu \
--cc=drow@mvista.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox