This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix error-recovery in cp_make_fname_decl (PR c++/46538)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 18 Nov 2010 21:44:47 +0100
- Subject: [C++ PATCH] Fix error-recovery in cp_make_fname_decl (PR c++/46538)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
On this invalid testcase current_binding_level has sk_function_parms
kind and thus the loop crashes as it doesn't find any level of such
kind in the outer levels.
Fixed just by returning error_mark_node in that case, if needed it could
assert that errorcount is non-zero.
2010-11-18 Jakub Jelinek <jakub@redhat.com>
PR c++/46538
* decl.c (cp_make_fname_decl): Return error_mark_node if
current_binding_level has already sk_function_parms kind.
* g++.dg/other/error34.C: New test.
--- gcc/cp/decl.c.jj 2010-11-17 10:13:16.000000000 +0100
+++ gcc/cp/decl.c 2010-11-18 18:49:28.079655004 +0100
@@ -3687,6 +3687,8 @@ cp_make_fname_decl (location_t loc, tree
if (current_function_decl)
{
struct cp_binding_level *b = current_binding_level;
+ if (b->kind == sk_function_parms)
+ return error_mark_node;
while (b->level_chain->kind != sk_function_parms)
b = b->level_chain;
pushdecl_with_scope (decl, b, /*is_friend=*/false);
--- gcc/testsuite/g++.dg/other/error34.C.jj 2010-11-18 18:53:17.692255213 +0100
+++ gcc/testsuite/g++.dg/other/error34.C 2010-11-18 18:52:41.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/46538
+// { dg-do compile }
+// { dg-options "" }
+
+S () : str(__PRETTY_FUNCTION__) {} // { dg-error "forbids declaration" }
+// { dg-error "only constructors" "" { target *-*-* } 5 }
Jakub