]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/60361 (unexpected 'use of parameter outside function body' error)
authorJason Merrill <jason@redhat.com>
Fri, 1 Aug 2014 18:33:35 +0000 (14:33 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 1 Aug 2014 18:33:35 +0000 (14:33 -0400)
PR c++/60361
* parser.c (cp_parser_template_id): Don't set up a CPP_TEMPLATE_ID
if re-parsing might succeed.
* semantics.c (finish_id_expression): Use of a parameter outside
the function body is a parse error.

From-SVN: r213499

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

index 48084942cd71fe5f56cfd7ec69dd931bdf449097..eda7f4e2e90bff1bf2be4d83b51acd16acbbc0d8 100644 (file)
@@ -1,3 +1,11 @@
+2014-03-05  Jason Merrill  <jason@redhat.com>
+
+       PR c++/60361
+       * parser.c (cp_parser_template_id): Don't set up a CPP_TEMPLATE_ID
+       if re-parsing might succeed.
+       * semantics.c (finish_id_expression): Use of a parameter outside
+       the function body is a parse error.
+
 2014-06-30  Jason Merrill  <jason@redhat.com>
 
        PR c++/61647
index c512d69c6a68da07d3ec02c5342a0194cfff383d..affe2df0c4719282a4edaf5333cf0dedb0a98982 100644 (file)
@@ -12831,7 +12831,12 @@ cp_parser_template_id (cp_parser *parser,
      the effort required to do the parse, nor will we issue duplicate
      error messages about problems during instantiation of the
      template.  */
-  if (start_of_id)
+  if (start_of_id
+      /* Don't do this if we had a parse error in a declarator; re-parsing
+        might succeed if a name changes meaning (60361).  */
+      && !(cp_parser_error_occurred (parser)
+          && cp_parser_parsing_tentatively (parser)
+          && parser->in_declarator_p))
     {
       cp_token *token = cp_lexer_token_at (parser->lexer, start_of_id);
 
index 9518685337495cf2bc658a1047d7659e40c0169d..d5013c446f9fb3bb4749cd995ecca05218683264 100644 (file)
@@ -3108,7 +3108,7 @@ finish_id_expression (tree id_expression,
          && DECL_CONTEXT (decl) == NULL_TREE
          && !cp_unevaluated_operand)
        {
-         error ("use of parameter %qD outside function body", decl);
+         *error_msg = "use of parameter outside function body";
          return error_mark_node;
        }
     }
diff --git a/gcc/testsuite/g++.dg/parse/ambig7.C b/gcc/testsuite/g++.dg/parse/ambig7.C
new file mode 100644 (file)
index 0000000..9a5b879
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/60361
+
+struct Helper
+{
+  Helper(int a, void (*pfunc)());
+};
+
+template <int I> void function();
+
+const int A = 1;
+const int B = 2;
+
+Helper testOk(A, function<A>);
+Helper testOk2(int(A), function<B>);
+Helper testOk3((int(A)), function<A>);
+Helper testFail(int(A), function<A>);
index 6116630433f3d5c825258f68f74842c4e967047f..3c983cc748c4cc0d7409085834e67f734b414159 100644 (file)
@@ -1,2 +1,2 @@
-void f (int i, int p[i]); // { dg-error "use of parameter .i. outside function body" }
+void f (int i, int p[i]); // { dg-error "use of parameter.*outside function body" }
 // { dg-prune-output "array bound" }
index 2d823f8078e5844e331b9b3f3c49a86c47c55a3a..3cee4bac68bf7fbbe1b10b2e7bffa7ae9b7ce2a2 100644 (file)
@@ -7,10 +7,9 @@
 
 struct A
 {
-  template<typename>   void foo(int); // { dg-message "note" }
-  template<typename T> void bar(T t) { // { dg-message "note" }
+  template<typename>   void foo(int);
+  template<typename T> void bar(T t) {
     this->foo<typename T>(t); } // { dg-error "expected|parse error|no matching" }
-  // { dg-message "candidate" "candidate note" { target *-*-* } 12 }
   template<typename T> void bad(T t) {
     foo<typename T>(t); } // { dg-error "expected|parse error|no matching" }
 };
@@ -20,7 +19,6 @@ struct B
 {
   void bar(T t) {
     A().bar<typename T>(t); } // { dg-error "expected|parse error|no matching" }
-  // { dg-message "candidate" "candidate note" { target *-*-* } 22 }
   void bad(T t) {
     B<typename T>::bar(t); } // { dg-error "invalid|not a template" }
 };