Patchwork [C++] Fix error-recovery in cp_make_fname_decl (PR c++/46538)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 18, 2010, 8:44 p.m.
Message ID <20101118204447.GC29412@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/72146/
State New
Headers show

Comments

Jakub Jelinek - Nov. 18, 2010, 8:44 p.m.
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.


	Jakub
Jason Merrill - Nov. 20, 2010, 2:05 a.m.
OK.

Jason

Patch

--- 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 }