From da9bc840f694868fa1e84ef6a92ebc79b1faa64a Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 15 Sep 2010 19:55:49 -0400 Subject: [PATCH] semantics.c (finish_id_expression): Diagnose use of function parms in evaluated context outside function body. * semantics.c (finish_id_expression): Diagnose use of function parms in evaluated context outside function body. From-SVN: r164322 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/semantics.c | 10 ++++++++++ gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/parse/parameter-declaration-2.C | 1 + 4 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/parameter-declaration-2.C 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" } -- 2.11.4.GIT