|
|
727081 |
2006-08-09 Alexandre Oliva <aoliva@redhat.com>
|
|
|
727081 |
|
|
|
727081 |
* function.c (do_warn_unused_parameter): Do not issue warnings
|
|
|
727081 |
for declarations in system headers.
|
|
|
727081 |
|
|
|
727081 |
2006-02-22 Alexandre Oliva <aoliva@redhat.com>
|
|
|
727081 |
|
|
|
727081 |
Backport and tweak:
|
|
|
727081 |
2004-05-06 Jan Hubicka <jh@suse.cz>
|
|
|
727081 |
PR c/15004
|
|
|
727081 |
* function.c (do_warn_unused_parameter): Break out form ...
|
|
|
727081 |
(expand_function_end): ... here.
|
|
|
727081 |
* function.h (do_warn_unused_parameter): Declare.
|
|
|
727081 |
|
|
|
727081 |
2006-02-22 Alexandre Oliva <aoliva@redhat.com>
|
|
|
727081 |
|
|
|
727081 |
* decl2.c (finish_file): Issue warnings for unused parameters
|
|
|
727081 |
of functions not expanded.
|
|
|
727081 |
|
|
|
727081 |
* g++.dg/Wunused-parm-1.C: New.
|
|
|
727081 |
|
|
|
727081 |
--- gcc/cp/decl2.c.orig 2003-08-12 11:12:25.000000000 -0300
|
|
|
727081 |
+++ gcc/cp/decl2.c 2006-08-09 16:59:09.000000000 -0300
|
|
|
727081 |
@@ -3551,6 +3551,17 @@ finish_file ()
|
|
|
727081 |
}
|
|
|
727081 |
while (reconsider);
|
|
|
727081 |
|
|
|
727081 |
+ if (warn_unused_parameter)
|
|
|
727081 |
+ for (i = 0; i < deferred_fns_used; ++i)
|
|
|
727081 |
+ {
|
|
|
727081 |
+ tree decl = VARRAY_TREE (deferred_fns, i);
|
|
|
727081 |
+
|
|
|
727081 |
+ /* Warn about unused parameters in functions we refrained from
|
|
|
727081 |
+ synthesizing. */
|
|
|
727081 |
+ if (!TREE_ASM_WRITTEN (decl))
|
|
|
727081 |
+ do_warn_unused_parameter (decl);
|
|
|
727081 |
+ }
|
|
|
727081 |
+
|
|
|
727081 |
/* We give C linkage to static constructors and destructors. */
|
|
|
727081 |
push_lang_context (lang_name_c);
|
|
|
727081 |
|
|
|
727081 |
--- gcc/function.c.orig 2003-10-31 08:42:15.000000000 -0200
|
|
|
727081 |
+++ gcc/function.c 2006-08-10 00:28:06.000000000 -0300
|
|
|
727081 |
@@ -6808,6 +6808,27 @@ use_return_register ()
|
|
|
727081 |
diddle_return_value (do_use_return_reg, NULL);
|
|
|
727081 |
}
|
|
|
727081 |
|
|
|
727081 |
+/* Warn about unused parms if extra warnings were specified. */
|
|
|
727081 |
+/* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
|
|
|
727081 |
+ warning. WARN_UNUSED_PARAMETER is negative when set by
|
|
|
727081 |
+ -Wunused. */
|
|
|
727081 |
+void
|
|
|
727081 |
+do_warn_unused_parameter (tree fn)
|
|
|
727081 |
+{
|
|
|
727081 |
+ if (warn_unused_parameter > 0
|
|
|
727081 |
+ || (warn_unused_parameter < 0 && extra_warnings))
|
|
|
727081 |
+ {
|
|
|
727081 |
+ tree decl;
|
|
|
727081 |
+
|
|
|
727081 |
+ for (decl = DECL_ARGUMENTS (fn);
|
|
|
727081 |
+ decl; decl = TREE_CHAIN (decl))
|
|
|
727081 |
+ if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
|
|
|
727081 |
+ && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)
|
|
|
727081 |
+ && ! DECL_IN_SYSTEM_HEADER (decl))
|
|
|
727081 |
+ warning_with_decl (decl, "unused parameter `%s'");
|
|
|
727081 |
+ }
|
|
|
727081 |
+}
|
|
|
727081 |
+
|
|
|
727081 |
/* Generate RTL for the end of the current function.
|
|
|
727081 |
FILENAME and LINE are the current position in the source file.
|
|
|
727081 |
|
|
|
727081 |
@@ -6907,21 +6928,8 @@ expand_function_end (filename, line, end
|
|
|
727081 |
}
|
|
|
727081 |
}
|
|
|
727081 |
|
|
|
727081 |
- /* Warn about unused parms if extra warnings were specified. */
|
|
|
727081 |
- /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
|
|
|
727081 |
- warning. WARN_UNUSED_PARAMETER is negative when set by
|
|
|
727081 |
- -Wunused. */
|
|
|
727081 |
- if (warn_unused_parameter > 0
|
|
|
727081 |
- || (warn_unused_parameter < 0 && extra_warnings))
|
|
|
727081 |
- {
|
|
|
727081 |
- tree decl;
|
|
|
727081 |
-
|
|
|
727081 |
- for (decl = DECL_ARGUMENTS (current_function_decl);
|
|
|
727081 |
- decl; decl = TREE_CHAIN (decl))
|
|
|
727081 |
- if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
|
|
|
727081 |
- && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
|
|
|
727081 |
- warning_with_decl (decl, "unused parameter `%s'");
|
|
|
727081 |
- }
|
|
|
727081 |
+ if (warn_unused_parameter)
|
|
|
727081 |
+ do_warn_unused_parameter (current_function_decl);
|
|
|
727081 |
|
|
|
727081 |
/* Delete handlers for nonlocal gotos if nothing uses them. */
|
|
|
727081 |
if (nonlocal_goto_handler_slots != 0
|
|
|
727081 |
--- gcc/function.h.orig 2003-06-11 09:56:49.000000000 -0300
|
|
|
727081 |
+++ gcc/function.h 2006-08-09 16:59:09.000000000 -0300
|
|
|
727081 |
@@ -614,3 +614,5 @@ extern void init_virtual_regs PARAMS ((
|
|
|
727081 |
|
|
|
727081 |
/* Called once, at initialization, to initialize function.c. */
|
|
|
727081 |
extern void init_function_once PARAMS ((void));
|
|
|
727081 |
+
|
|
|
727081 |
+extern void do_warn_unused_parameter PARAMS ((tree));
|
|
|
727081 |
--- gcc/testsuite/g++.dg/warn/Wunused-parm-1.C 1970-01-01 00:00:00.000000000 +0000
|
|
|
727081 |
+++ gcc/testsuite/g++.dg/warn/Wunused-parm-1.C 2006-08-09 16:59:09.000000000 -0300
|
|
|
727081 |
@@ -0,0 +1,27 @@
|
|
|
727081 |
+// Test whether we issue warnings for unused parameters, even for
|
|
|
727081 |
+// inline functions that are not emitted (without optimization, we
|
|
|
727081 |
+// always emit them).
|
|
|
727081 |
+// { dg-do compile }
|
|
|
727081 |
+// { dg-options "-Wunused-parameter -O" }
|
|
|
727081 |
+
|
|
|
727081 |
+static inline int foo(int var) { // { dg-warning "unused parameter" }
|
|
|
727081 |
+ return 0;
|
|
|
727081 |
+}
|
|
|
727081 |
+
|
|
|
727081 |
+static inline int foo2(int var) { // { dg-warning "unused parameter" }
|
|
|
727081 |
+ return 0;
|
|
|
727081 |
+}
|
|
|
727081 |
+
|
|
|
727081 |
+static inline int bar(int var) {
|
|
|
727081 |
+ return var;
|
|
|
727081 |
+}
|
|
|
727081 |
+
|
|
|
727081 |
+static inline int bar2(int var) {
|
|
|
727081 |
+ return var;
|
|
|
727081 |
+}
|
|
|
727081 |
+
|
|
|
727081 |
+int main() {
|
|
|
727081 |
+ foo (1);
|
|
|
727081 |
+ bar (2);
|
|
|
727081 |
+ return 0;
|
|
|
727081 |
+}
|