C++ PATCH: PR 17155

Mark Mitchell mark@codesourcery.com
Wed Aug 25 20:53:00 GMT 2004


This patch fixes further fallout from the conversion to unit-at-a-time
in the C++ front end.  It turns out that the middle end decided that
functions in local classes did not have constant addresses.  That's
fixed by setting DECL_NO_STATIC_CHAIN for all C++ functions.

However, I think this is a non-ideal design.  The middle end is
presently assuming that any function with a non-NULL
decl_function_context is a GNU C-style nested function, unless
DECL_NO_STATIC_CHAIN is set.  It would seem superior just to have a
DECL_STATIC_CHAIN bit and require front ends to set it when they want
that behavior.  That would be both more efficient and more explicit.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com


2004-08-25  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17155
	* lex.c (build_lang_decl): Set DECL_NO_STATIC_CHAIN for all C++
	functions.

2004-08-25  Mark Mitchell  <mark@codesourcery.com>

	PR c++/17155
	* g++.dg/inherit/local2.C: New test.

Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.340
diff -c -5 -p -r1.340 lex.c
*** cp/lex.c	19 Aug 2004 10:36:05 -0000	1.340
--- cp/lex.c	25 Aug 2004 19:33:06 -0000
*************** build_lang_decl (enum tree_code code, tr
*** 647,656 ****
--- 647,661 ----
    tree t;
  
    t = build_decl (code, name, type);
    retrofit_lang_decl (t);
  
+   /* All nesting of C++ functions is lexical; there is never a "static
+      chain" in the sense of GNU C nested functions.  */
+   if (code == FUNCTION_DECL) 
+     DECL_NO_STATIC_CHAIN (t) = 1;
+ 
    return t;
  }
  
  /* Add DECL_LANG_SPECIFIC info to T.  Called from build_lang_decl
     and pushdecl (for functions generated by the backend).  */
Index: testsuite/g++.dg/inherit/local2.C
===================================================================
RCS file: testsuite/g++.dg/inherit/local2.C
diff -N testsuite/g++.dg/inherit/local2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/inherit/local2.C	25 Aug 2004 19:33:10 -0000
***************
*** 0 ****
--- 1,16 ----
+ // PR c++/17155
+ // { dg-do link }
+ 
+ struct A {
+   virtual ~A() {}
+ };
+ 
+ 
+ void tsk_tsk(void)
+ {
+   struct B : public A {
+     B(int) {}
+   };
+ }
+ 
+ int main () {}



More information about the Gcc-patches mailing list