This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix bogus C++ warning
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Fix bogus C++ warning
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 12 Nov 2001 16:02:53 +0100
- Cc: hjl at gnu dot org
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
C++ warns in the testcase below:
warning: the address of `void foo()', will always be `true'
which is bogus.
Dunno why H.J. hasn't submitted this, ok to commit?
2001-08-03 H.J. Lu <hjl@gnu.org>
* cvt.c (ocp_convert): Don't warn the address of a weak
function is always `true'.
* g++.dg/warn/weak1.C: New test.
--- gcc/cp/cvt.c.jj Sat Aug 18 22:10:48 2001
+++ gcc/cp/cvt.c Fri Oct 12 17:30:50 2001
@@ -814,7 +814,7 @@ ocp_convert (type, expr, convtype, flags
else if (TREE_CODE (expr) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
fn = TREE_OPERAND (expr, 0);
- if (fn)
+ if (fn && !DECL_WEAK (fn))
cp_warning ("the address of `%D', will always be `true'", fn);
return cp_truthvalue_conversion (e);
}
--- gcc/testsuite/g++.dg/warn/weak1.C.jj Fri Oct 12 17:30:50 2001
+++ gcc/testsuite/g++.dg/warn/weak1.C Fri Oct 12 17:30:50 2001
@@ -0,0 +1,12 @@
+// { dg-do run }
+
+extern void foo (void) __attribute__ ((weak));
+
+int
+main ()
+{
+ if (&foo)
+ foo ();
+
+ return 0;
+}
Jakub