@@ -869,7 +869,10 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator
if (ctype) {
if (is_safe_type(ctype))
warning(expr->pos, "testing a 'safe expression'");
- if (!is_scalar_type(ctype)) {
+ if (is_func_type(ctype)) {
+ if (Waddress)
+ warning(expr->pos, "the address of %s will always evaluate as true", "a function");
+ } else if (!is_scalar_type(ctype)) {
sparse_error(expr->pos, "incorrect type in conditional");
info(expr->pos, " got %s", show_typename(ctype));
ctype = NULL;
new file mode 100644
@@ -0,0 +1,18 @@
+extern void func(void);
+
+int global_function(void)
+{
+ if (func)
+ return 1;
+ return 0;
+}
+
+/*
+ * check-name: cond-address-function
+ * check-command: test-linearize -Wno-decl -Waddress $file
+ * check-output-ignore
+ *
+ * check-error-start
+cond-address-function.c:5:13: warning: the address of a function will always evaluate as true
+ * check-error-end
+ */
Testing the address of a function is quite suspicious: it's most probably the sign of an error somewhere. Furthermore, such uses always evaluate to true. So, add a warning about such use (but only if -Waddress was given). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- evaluate.c | 5 ++++- validation/cond-address-function.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 validation/cond-address-function.c