commit ff67fd57b978582fcc5f8818a8192a25c507ac34
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Sep 15 16:07:37 2010 -0400

    	* semantics.c (finish_id_expression): Diagnose use of function
    	parms in evaluated context outside function body.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index dc81568..b73dffb 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2864,6 +2864,16 @@ finish_id_expression (tree id_expression,
 	      return error_mark_node;
 	    }
 	}
+
+      /* Also disallow uses of function parameters outside the function
+	 body, except inside an unevaluated context (i.e. decltype).  */
+      if (TREE_CODE (decl) == PARM_DECL
+	  && DECL_CONTEXT (decl) == NULL_TREE
+	  && !cp_unevaluated_operand)
+	{
+	  error ("use of parameter %qD outside function body", decl);
+	  return error_mark_node;
+	}
     }
 
   /* If we didn't find anything, or what we found was a type,
diff --git a/gcc/testsuite/g++.dg/parse/parameter-declaration-2.C b/gcc/testsuite/g++.dg/parse/parameter-declaration-2.C
new file mode 100644
index 0000000..7a9a24f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/parameter-declaration-2.C
@@ -0,0 +1 @@
+void f (int i, int p[i]); // { dg-error "use of parameter .i. outside function body" }
