Commit cd6311ef by Zack Weinberg Committed by Zack Weinberg

c-typeck.c (build_c_cast): Issue -Wcast-qual warnings if the qualifiers don't…

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
parent f668c81c
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
* cccp.c: Accept and ignore -lang-fortran. * 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> 2000-01-12 Robert Lipe <robertl@sco.com>
* i386/sysv5.h (CPP_SPEC, LIBSPEC): Add -pthreadT. * i386/sysv5.h (CPP_SPEC, LIBSPEC): Add -pthreadT.
......
...@@ -3701,16 +3701,24 @@ build_c_cast (type, expr) ...@@ -3701,16 +3701,24 @@ build_c_cast (type, expr)
&& TREE_CODE (type) == POINTER_TYPE && TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE) && TREE_CODE (otype) == POINTER_TYPE)
{ {
/* Go to the innermost object being pointed to. */
tree in_type = type; tree in_type = type;
tree in_otype = otype; tree in_otype = otype;
int warn = 0;
while (TREE_CODE (in_type) == POINTER_TYPE) /* Check that the qualifiers on IN_TYPE are a superset of
in_type = TREE_TYPE (in_type); the qualifiers of IN_OTYPE. The outermost level of
while (TREE_CODE (in_otype) == POINTER_TYPE) POINTER_TYPE nodes is uninteresting and we stop as soon
in_otype = TREE_TYPE (in_otype); as we hit a non-POINTER_TYPE node on either type. */
do
if (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type)) {
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 /* There are qualifiers present in IN_OTYPE that are not
present in IN_TYPE. */ present in IN_TYPE. */
pedwarn ("cast discards qualifiers from pointer target type"); pedwarn ("cast discards qualifiers from pointer target type");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment