Commit 5d264d62 by Jason Merrill Committed by Jason Merrill

re PR c++/60361 (unexpected 'use of parameter outside function body' error)

	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: r208351
parent 04702386
2014-03-05 Jason Merrill <jason@redhat.com> 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.
* parser.c (cp_parser_mem_initializer): Set input_location * parser.c (cp_parser_mem_initializer): Set input_location
properly for init-list warning. properly for init-list warning.
(cp_parser_postfix_open_square_expression): Likewise. (cp_parser_postfix_open_square_expression): Likewise.
......
...@@ -13466,7 +13466,12 @@ cp_parser_template_id (cp_parser *parser, ...@@ -13466,7 +13466,12 @@ cp_parser_template_id (cp_parser *parser,
the effort required to do the parse, nor will we issue duplicate the effort required to do the parse, nor will we issue duplicate
error messages about problems during instantiation of the error messages about problems during instantiation of the
template. */ 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); cp_token *token = cp_lexer_token_at (parser->lexer, start_of_id);
......
...@@ -3246,7 +3246,7 @@ finish_id_expression (tree id_expression, ...@@ -3246,7 +3246,7 @@ finish_id_expression (tree id_expression,
&& DECL_CONTEXT (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
&& !cp_unevaluated_operand) && !cp_unevaluated_operand)
{ {
error ("use of parameter %qD outside function body", decl); *error_msg = "use of parameter outside function body";
return error_mark_node; return error_mark_node;
} }
} }
......
// 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>);
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" } // { dg-prune-output "array bound" }
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
struct A struct A
{ {
template<typename> void foo(int); // { dg-message "note" } template<typename> void foo(int);
template<typename T> void bar(T t) { // { dg-message "note" } template<typename T> void bar(T t) {
this->foo<typename T>(t); } // { dg-error "expected|parse error|no matching" } 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) { template<typename T> void bad(T t) {
foo<typename T>(t); } // { dg-error "expected|parse error|no matching" } foo<typename T>(t); } // { dg-error "expected|parse error|no matching" }
}; };
...@@ -20,7 +19,6 @@ struct B ...@@ -20,7 +19,6 @@ struct B
{ {
void bar(T t) { void bar(T t) {
A().bar<typename T>(t); } // { dg-error "expected|parse error|no matching" } A().bar<typename T>(t); } // { dg-error "expected|parse error|no matching" }
// { dg-message "candidate" "candidate note" { target *-*-* } 22 }
void bad(T t) { void bad(T t) {
B<typename T>::bar(t); } // { dg-error "invalid|qualified-id|not a template" } B<typename T>::bar(t); } // { dg-error "invalid|qualified-id|not a template" }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment