aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2001-04-10 22:40:48 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2001-04-10 22:40:48 +0000
commit03829ad289cd82c9780720a5ac786576f8a3057e (patch)
tree14f371b41420981a5b3bd6f53eea6248dabb7a20
parent5a01d63496ac7664a6b6cff8b59fb37fe0f14fdd (diff)
downloadgcc-03829ad289cd82c9780720a5ac786576f8a3057e.zip
gcc-03829ad289cd82c9780720a5ac786576f8a3057e.tar.gz
gcc-03829ad289cd82c9780720a5ac786576f8a3057e.tar.bz2
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
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-typeck.c21
-rw-r--r--gcc/invoke.texi5
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/wtr-conversion-1.c88
5 files changed, 121 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index da7a4ab..4785163 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 508045b..400e80d 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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);
+ }
}
}
diff --git a/gcc/invoke.texi b/gcc/invoke.texi
index d3c179b..8ce73e4 100644
--- a/gcc/invoke.texi
+++ b/gcc/invoke.texi
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 94c8ff1..842a4b5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gcc.dg/wtr-conversion-1.c b/gcc/testsuite/gcc.dg/wtr-conversion-1.c
new file mode 100644
index 0000000..57dd818
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wtr-conversion-1.c
@@ -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);
+}