mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-12 07:10:26 +08:00
c-typeck.c (convert_arguments): -Wtraditional now activates -Wconversion warnings...
* c-typeck.c (convert_arguments): -Wtraditional now activates -Wconversion warnings, except for changes in signed-ness. Detect complex<->int & int<->complex conversions as well. * invoke.texi (-Wtraditional): Document it. testsuite: * gcc.dg/wtr-conversion-1.c: New testcase. From-SVN: r41232
This commit is contained in:
parent
5a01d63496
commit
03829ad289
@ -1,3 +1,11 @@
|
||||
2001-04-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* c-typeck.c (convert_arguments): -Wtraditional now activates
|
||||
-Wconversion warnings, except for changes in signed-ness.
|
||||
Detect complex<->int & int<->complex conversions as well.
|
||||
|
||||
* invoke.texi (-Wtraditional): Document it.
|
||||
|
||||
Tue Apr 10 17:45:50 2001 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
|
||||
|
||||
* gcse.c (update_ld_motion_stores): Don't use variable I for an insn.
|
||||
|
@ -1676,19 +1676,25 @@ convert_arguments (typelist, values, name, fundecl)
|
||||
{
|
||||
/* Optionally warn about conversions that
|
||||
differ from the default conversions. */
|
||||
if (warn_conversion)
|
||||
if (warn_conversion || warn_traditional)
|
||||
{
|
||||
int formal_prec = TYPE_PRECISION (type);
|
||||
|
||||
if (INTEGRAL_TYPE_P (type)
|
||||
&& TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
|
||||
warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
|
||||
if (INTEGRAL_TYPE_P (type)
|
||||
&& TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
|
||||
warn_for_assignment ("%s as integer rather than complex due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else if (TREE_CODE (type) == COMPLEX_TYPE
|
||||
&& TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
|
||||
warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else if (TREE_CODE (type) == REAL_TYPE
|
||||
&& INTEGRAL_TYPE_P (TREE_TYPE (val)))
|
||||
warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else if (TREE_CODE (type) == COMPLEX_TYPE
|
||||
&& INTEGRAL_TYPE_P (TREE_TYPE (val)))
|
||||
warn_for_assignment ("%s as complex rather than integer due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else if (TREE_CODE (type) == REAL_TYPE
|
||||
&& TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
|
||||
warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1);
|
||||
@ -1749,10 +1755,15 @@ convert_arguments (typelist, values, name, fundecl)
|
||||
else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
|
||||
&& TREE_UNSIGNED (TREE_TYPE (val)))
|
||||
;
|
||||
else if (TREE_UNSIGNED (type))
|
||||
warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else
|
||||
warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
|
||||
/* These warnings are only activated with
|
||||
-Wconversion, not with -Wtraditional. */
|
||||
else if (warn_conversion)
|
||||
{
|
||||
if (TREE_UNSIGNED (type))
|
||||
warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
|
||||
else
|
||||
warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2122,6 +2122,11 @@ omitted. This is done under the assumption that the zero initializer in
|
||||
user code appears conditioned on e.g. @code{__STDC__} to avoid missing
|
||||
initializer warnings and relies on default initialization to zero in the
|
||||
traditional C case.
|
||||
|
||||
@item
|
||||
Conversions by prototypes. This is similar to @samp{-Wconversion} in
|
||||
that it warns about width changes and fixed/floating point conversions,
|
||||
however it does not warn about changes in signedness.
|
||||
@end itemize
|
||||
|
||||
@item -Wundef
|
||||
|
@ -1,3 +1,7 @@
|
||||
2001-04-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* gcc.dg/wtr-conversion-1.c: New testcase.
|
||||
|
||||
2001-04-10 Richard Henderson <rth@redhat.com>
|
||||
|
||||
* g++.old-deja/g++.other/array5.C: New.
|
||||
|
88
gcc/testsuite/gcc.dg/wtr-conversion-1.c
Normal file
88
gcc/testsuite/gcc.dg/wtr-conversion-1.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* Test for -Wtraditional warnings on conversions by prototypes.
|
||||
Note, gcc should omit these warnings in system header files.
|
||||
By Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 4/09/2001. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wtraditional" } */
|
||||
|
||||
extern void foo_c (char);
|
||||
extern void foo_ll (long long);
|
||||
extern void foo_f (float);
|
||||
extern void foo_ld (long double);
|
||||
extern void foo_cd (__complex__ double);
|
||||
|
||||
extern char c;
|
||||
extern long long ll;
|
||||
extern float f;
|
||||
extern long double ld;
|
||||
extern __complex__ double cd;
|
||||
|
||||
void
|
||||
testfunc1 (void)
|
||||
{
|
||||
foo_c (c); /* { dg-warning "with different width" "prototype conversion warning" } */
|
||||
foo_c (ll); /* { dg-warning "with different width" "prototype conversion warning" } */
|
||||
foo_c (f); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
|
||||
foo_c (ld); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
|
||||
foo_c (cd); /* { dg-warning "as integer rather than complex" "prototype conversion warning" } */
|
||||
|
||||
foo_ll (c); /* { dg-warning "with different width" "prototype conversion warning" } */
|
||||
foo_ll (ll);
|
||||
foo_ll (f); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
|
||||
foo_ll (ld); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
|
||||
foo_ll (cd); /* { dg-warning "as integer rather than complex" "prototype conversion warning" } */
|
||||
|
||||
foo_f (c); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
|
||||
foo_f (ll); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
|
||||
foo_f (f); /* { dg-warning "as `float' rather than `double'" "prototype conversion warning" } */
|
||||
foo_f (ld); /* { dg-warning "as `float' rather than `double'" "prototype conversion warning" } */
|
||||
foo_f (cd); /* { dg-warning "as floating rather than complex" "prototype conversion warning" } */
|
||||
|
||||
foo_ld (c); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
|
||||
foo_ld (ll); /* { dg-warning "as floating rather than integer" "prototype conversion warning" } */
|
||||
foo_ld (f);
|
||||
foo_ld (ld);
|
||||
foo_ld (cd); /* { dg-warning "as floating rather than complex" "prototype conversion warning" } */
|
||||
|
||||
foo_cd (c); /* { dg-warning "as complex rather than integer" "prototype conversion warning" } */
|
||||
foo_cd (ll); /* { dg-warning "as complex rather than integer" "prototype conversion warning" } */
|
||||
foo_cd (f); /* { dg-warning "as complex rather than floating" "prototype conversion warning" } */
|
||||
foo_cd (ld); /* { dg-warning "as complex rather than floating" "prototype conversion warning" } */
|
||||
foo_cd (cd);
|
||||
}
|
||||
|
||||
# 54 "sys-header.h" 3
|
||||
/* We are in system headers now, no -Wtraditional warnings should issue. */
|
||||
|
||||
void
|
||||
testfunc2 (void)
|
||||
{
|
||||
foo_c (c);
|
||||
foo_c (ll);
|
||||
foo_c (f);
|
||||
foo_c (ld);
|
||||
foo_c (cd);
|
||||
|
||||
foo_ll (c);
|
||||
foo_ll (ll);
|
||||
foo_ll (f);
|
||||
foo_ll (ld);
|
||||
foo_ll (cd);
|
||||
|
||||
foo_f (c);
|
||||
foo_f (ll);
|
||||
foo_f (f);
|
||||
foo_f (ld);
|
||||
foo_f (cd);
|
||||
|
||||
foo_ld (c);
|
||||
foo_ld (ll);
|
||||
foo_ld (f);
|
||||
foo_ld (ld);
|
||||
foo_ld (cd);
|
||||
|
||||
foo_cd (c);
|
||||
foo_cd (ll);
|
||||
foo_cd (f);
|
||||
foo_cd (ld);
|
||||
foo_cd (cd);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user