From af702de897e40d55efee12aafd7a9d797c52d49c Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Mon, 4 Feb 2002 17:01:30 +0000 Subject: [PATCH] c-typeck.c (build_c_cast): Warn when qualifiers are added to function types, not when they're taken away. * c-typeck.c (build_c_cast): Warn when qualifiers are added to function types, not when they're taken away. From-SVN: r49481 --- gcc/ChangeLog | 5 +++++ gcc/c-typeck.c | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 63c0ce5..102e0ab 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2002-02-04 Richard Sandiford + + * c-typeck.c (build_c_cast): Warn when qualifiers are added to + function types, not when they're taken away. + Mon Feb 4 09:05:58 2002 Jeffrey A Law (law@redhat.com) * cfgrtl.c (try_redirect_by_replacing_jump): Remove associated diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 37f6a87..a00c724 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3819,7 +3819,8 @@ build_c_cast (type, expr) { tree in_type = type; tree in_otype = otype; - int warn = 0; + int added = 0; + int discarded = 0; /* Check that the qualifiers on IN_TYPE are a superset of the qualifiers of IN_OTYPE. The outermost level of @@ -3829,12 +3830,24 @@ build_c_cast (type, expr) { in_otype = TREE_TYPE (in_otype); in_type = TREE_TYPE (in_type); - warn |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type)); + + /* GNU C allows cv-qualified function types. 'const' + means the function is very pure, 'volatile' means it + can't return. We need to warn when such qualifiers + are added, not when they're taken away. */ + if (TREE_CODE (in_otype) == FUNCTION_TYPE + && TREE_CODE (in_type) == FUNCTION_TYPE) + added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype)); + else + discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type)); } while (TREE_CODE (in_type) == POINTER_TYPE && TREE_CODE (in_otype) == POINTER_TYPE); - if (warn) + if (added) + warning ("cast adds new qualifiers to function type"); + + if (discarded) /* There are qualifiers present in IN_OTYPE that are not present in IN_TYPE. */ warning ("cast discards qualifiers from pointer target type"); -- 2.7.4