OSDN Git Service

* semantics.c (finish_id_expression): Diagnose use of function
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 Sep 2010 23:55:49 +0000 (23:55 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 Sep 2010 23:55:49 +0000 (23:55 +0000)
parms in evaluated context outside function body.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164322 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/parameter-declaration-2.C [new file with mode: 0644]

index 10630c2..c412f0c 100644 (file)
@@ -1,5 +1,8 @@
 2010-09-15  Jason Merrill  <jason@redhat.com>
 
+       * 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
index dc81568..b73dffb 100644 (file)
@@ -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,
index 486c945..e41832b 100644 (file)
@@ -1,5 +1,7 @@
 2010-09-15  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/parse/parameter-declaration-2.C: New.
+
        * g++.dg/cpp0x/scoped_enum2.C: New.
 
 2010-09-15  Eric Botcazou  <ebotcazou@adacore.com>
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 (file)
index 0000000..7a9a24f
--- /dev/null
@@ -0,0 +1 @@
+void f (int i, int p[i]); // { dg-error "use of parameter .i. outside function body" }