aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-01-12 17:35:41 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-01-12 17:35:41 +0000
commitcd6311ef6edcaf65e88a0427f3368a7e8224b1df (patch)
tree9a787e4922adb3937e2386122c671a13db6b2b07
parentf668c81cda01a89410ae4b02364065be5b34cfc2 (diff)
downloadgcc-cd6311ef6edcaf65e88a0427f3368a7e8224b1df.zip
gcc-cd6311ef6edcaf65e88a0427f3368a7e8224b1df.tar.gz
gcc-cd6311ef6edcaf65e88a0427f3368a7e8224b1df.tar.bz2
c-typeck.c (build_c_cast): Issue -Wcast-qual warnings if the qualifiers don't match at any level of...
* c-typeck.c (build_c_cast): Issue -Wcast-qual warnings if the qualifiers don't match at any level of pointerness. From-SVN: r31356
-rw-r--r--gcc/ChangeLog3
-rw-r--r--gcc/c-typeck.c22
2 files changed, 18 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ac8d0b4..4ce5ffe 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -2,6 +2,9 @@
* cccp.c: Accept and ignore -lang-fortran.
+ * c-typeck.c (build_c_cast): Issue -Wcast-qual warnings if the
+ qualifiers don't match at any level of pointerness.
+
2000-01-12 Robert Lipe <robertl@sco.com>
* i386/sysv5.h (CPP_SPEC, LIBSPEC): Add -pthreadT.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 0529d2a..e0e4df4 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3701,16 +3701,24 @@ build_c_cast (type, expr)
&& TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE)
{
- /* Go to the innermost object being pointed to. */
tree in_type = type;
tree in_otype = otype;
+ int warn = 0;
- while (TREE_CODE (in_type) == POINTER_TYPE)
- in_type = TREE_TYPE (in_type);
- while (TREE_CODE (in_otype) == POINTER_TYPE)
- in_otype = TREE_TYPE (in_otype);
-
- if (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type))
+ /* Check that the qualifiers on IN_TYPE are a superset of
+ the qualifiers of IN_OTYPE. The outermost level of
+ POINTER_TYPE nodes is uninteresting and we stop as soon
+ as we hit a non-POINTER_TYPE node on either type. */
+ do
+ {
+ in_otype = TREE_TYPE (in_otype);
+ in_type = TREE_TYPE (in_type);
+ warn |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
+ }
+ while (TREE_CODE (in_type) == POINTER_TYPE
+ && TREE_CODE (in_otype) == POINTER_TYPE);
+
+ if (warn)
/* There are qualifiers present in IN_OTYPE that are not
present in IN_TYPE. */
pedwarn ("cast discards qualifiers from pointer target type");