This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/35579] [4.1/4.2/4.3/4.4 Regression] casts to void do not silence -Wunused warnings for the case of __attribute__(( warn_unused_result ))
- From: "bonzini at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Oct 2008 11:12:06 -0000
- Subject: [Bug c/35579] [4.1/4.2/4.3/4.4 Regression] casts to void do not silence -Wunused warnings for the case of __attribute__(( warn_unused_result ))
- References: <bug-35579-15916@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from bonzini at gnu dot org 2008-10-17 11:12 -------
Totally untested patch.
Index: c-common.c
===================================================================
--- c-common.c (revisione 134435)
+++ c-common.c (copia locale)
@@ -6762,7 +6762,8 @@ c_warn_unused_result (tree *top_p)
ftype = TREE_TYPE (ftype);
}
- if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
+ if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype))
+ && !TREE_NO_WARNING (t))
{
if (fdecl)
warning (0, "%Hignoring return value of %qD, "
Index: c-convert.c
===================================================================
--- c-convert.c (revisione 134435)
+++ c-convert.c (copia locale)
@@ -96,7 +96,11 @@ convert (tree type, tree expr)
return error_mark_node;
}
if (code == VOID_TYPE)
- return fold_convert (type, e);
+ {
+ if (TREE_CODE (e) == CALL_EXPR)
+ TREE_NO_WARNING (e) == 1;
+ return fold_convert (type, e);
+ }
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
return fold (convert_to_integer (type, e));
if (code == BOOLEAN_TYPE)
Index: cp/cvt.c
===================================================================
--- cp/cvt.c (revisione 134435)
+++ cp/cvt.c (copia locale)
@@ -825,6 +825,7 @@ convert_to_void (tree expr, const char *
break;
case CALL_EXPR: /* We have a special meaning for volatile void fn(). */
+ TREE_NO_WARNING (expr) = 1;
break;
case INDIRECT_REF:
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35579