This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Apparent qualify_type() bug for C, but not for C++
Mark Mitchell <mark@codesourcery.com> writes:
> >>>>> "Greg" == Greg McGary <gkm@eng.ascend.com> writes:
>
> Greg> This change from last year introduced a bug in qualify_type:
>
> Yuck. That's definitely a bug. Sorry. Do you have a small
> test-case? It would be good to add one to the regression test-suite.
Yes, it's "yuck", but for reasons of cruftiness rather than bugginess.
It's more of a feint than a bug. I couldn't contrive a test case
because the failure to merge qualifiers is corrected later on by this
bit:
/* Merge const and volatile flags of the incoming types. */
result_type
= build_type_variant (result_type,
TREE_READONLY (op1) || TREE_READONLY (op2),
TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
I conclude that qualify_type() in c-typeck.c doesn't carry its weight.
Below is a patch that cleans it out altogether. In cp/typeck.c,
qualify_type() should remain since it is used in a different context
where it does something useful.
Sorry, but I appear to have cried "wolf" on this one. I'll be more
careful next time.
Wed Sep 15 23:35:02 1999 Greg McGary <gkm@gnu.org>
* c-typeck.c (qualify_type): Remove useless function.
(build_conditional_expr): Remove calls to qualify_type.
Index: c-typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-typeck.c,v
retrieving revision 1.37
diff -u -p -r1.37 c-typeck.c
--- c-typeck.c 1999/09/16 04:16:31 1.37
+++ c-typeck.c 1999/09/16 09:44:03
@@ -1,5 +1,5 @@
/* Build expressions with type checking for C compiler.
- Copyright (C) 1987, 88, 91-97, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1987, 88, 91-97, 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -44,7 +44,6 @@ Boston, MA 02111-1307, USA. */
message within this initializer. */
static int missing_braces_mentioned;
-static tree qualify_type PROTO((tree, tree));
static int comp_target_types PROTO((tree, tree));
static int function_types_compatible_p PROTO((tree, tree));
static int type_lists_compatible_p PROTO((tree, tree));
@@ -159,17 +158,6 @@ incomplete_type_error (value, type)
IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
}
}
-
-/* Return a variant of TYPE which has all the type qualifiers of LIKE
- as well as those of TYPE. */
-
-static tree
-qualify_type (type, like)
- tree type, like;
-{
- return c_build_qualified_type (type,
- TYPE_QUALS (type) | TYPE_QUALS (like));
-}
/* Return the common type of two types.
We assume that comptypes has already been done and returned 1;
@@ -3339,6 +3327,8 @@ build_conditional_expr (ifexp, op1, op2)
type2 = TREE_TYPE (op2);
code2 = TREE_CODE (type2);
+ /* Derive the type of the expression from its operands. Don't bother
+ about merging type qualifiers yet, since we'll do that next. */
/* Quickly detect the usual case where op1 and op2 have the same type
after promotion. */
if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
@@ -3365,21 +3355,21 @@ build_conditional_expr (ifexp, op1, op2)
result_type = common_type (type1, type2);
else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
&& TREE_CODE (orig_op1) != NOP_EXPR)
- result_type = qualify_type (type2, type1);
+ result_type = type2;
else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
&& TREE_CODE (orig_op2) != NOP_EXPR)
- result_type = qualify_type (type1, type2);
+ result_type = type1;
else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
{
if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
- result_type = qualify_type (type1, type2);
+ result_type = type1;
}
else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
{
if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
- result_type = qualify_type (type2, type1);
+ result_type = type2;
}
else
{