This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On a piece of code in C++ and nested functions


Steven Bosscher <s.bosscher@student.tudelft.nl> writes:

| Hi,
| 
| In cp/decl.c, there's the following piece of code to expand nested
| functions,
| 
|    979    /* Output any nested inline functions within this block
|    980       if they weren't already output.  */
|    981    for (decl = decls; decl; decl = TREE_CHAIN (decl))
|    982      if (TREE_CODE (decl) == FUNCTION_DECL
|    983          && ! TREE_ASM_WRITTEN (decl)
|    984          && DECL_INITIAL (decl) != NULL_TREE
|    985          && TREE_ADDRESSABLE (decl)
|    986          && decl_function_context (decl) == current_function_decl)
|    987        {
|    988          /* If this decl was copied from a file-scope decl
|    989             on account of a block-scope extern decl,
|    990             propagate TREE_ADDRESSABLE to the file-scope decl.  */
|    991          if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
|    992            TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
|    993          else
|    994            {
|    995              push_function_context ();
|    996              output_inline_function (decl);
|    997              pop_function_context ();
|    998            }
|    999        }
| 
| that hasn't been touched since revision 1.1.  The manual says that
| "Nested functions are not supported for GNU C++."  So what's the purpose
| of this code?  Can it be removed?

I would say that it is a leftover of the era when cc1plus started as
copy-n-paste of cc1.  Moreover, C++ provides clean and  standard ways
to implement inline nested-functions in terms of local classes. 
I would suggest to get rid of that piece of code.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]