In this testcase, while we're tentatively parsing a function declarator
we came across __FUNCTION__, tried to predeclare it, and failed because
we were in function parameter scope; then when we try again later it
fails again because we cached the error_mark_node. So don't try the
first time.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 4468227a2b30526e907664904378bec32ddef9e2
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Dec 9 12:30:19 2014 -0500
PR c++/64222
* parser.c (cp_parser_unqualified_id): Don't declare fname while
parsing function parms.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d1cd63f..7bd9477 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5207,7 +5207,10 @@ cp_parser_unqualified_id (cp_parser* parser,
case RID_PRETTY_FUNCTION_NAME:
case RID_C99_FUNCTION_NAME:
cp_lexer_consume_token (parser->lexer);
- finish_fname (token->u.value);
+ /* Don't try to declare this while tentatively parsing a function
+ declarator, as cp_make_fname_decl will fail. */
+ if (current_binding_level->kind != sk_function_parms)
+ finish_fname (token->u.value);
return token->u.value;
default:
diff --git a/gcc/testsuite/g++.dg/parse/fnname1.C b/gcc/testsuite/g++.dg/parse/fnname1.C
new file mode 100644
index 0000000..2c18c30
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/fnname1.C
@@ -0,0 +1,17 @@
+// PR c++/64222
+
+class A
+{
+public:
+ A (const char *, void *);
+};
+class B
+{
+public:
+ B (A);
+};
+void
+fn1 ()
+{
+ B a (A (__func__, 0));
+}