diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 10630c26fc5..c412f0c9ece 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2010-09-15 Jason Merrill + * semantics.c (finish_id_expression): Diagnose use of function + parms in evaluated context outside function body. + * decl2.c (grokbitfield): Diagnose non-integral width. * call.c (convert_like_real): Use the underlying type of the diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index dc815686c1e..b73dffb0560 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/ChangeLog b/gcc/testsuite/ChangeLog index 486c9450674..e41832bda1d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2010-09-15 Jason Merrill + * g++.dg/parse/parameter-declaration-2.C: New. + * g++.dg/cpp0x/scoped_enum2.C: New. 2010-09-15 Eric Botcazou 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 00000000000..7a9a24fb752 --- /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" }