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: C++: decl with initialization


On Sun, 2003-06-29 at 14:18, Gabriel Dos Reis wrote:
> 
> I have been studying the code in cp/decl.c:start_decl that handles
> initial declarations.  When a decl is initialized, the DECL_INITIAL is
> set to error_mark_node instead of the true real initializer.  Why and
> what are the benefits doing that instead of using the true initializer?

The true initializer isn't available when we create the initial DECL
node -- after all the declaration has to be in scope during the
processing of the initializer so that things like "void *p = &p;"
works.  There is code that wants to know whether or not the declaration
is initialized when the declaration is created.

With the new parser, it's probably possible to get rid of the trick you
mention above; I suspect that the context required could simply be
maintained in local variables in the parser.  (That didn't used to be
possible because in the YACC parser there's no such thing as "local
variables", except for using empty productions as places to store
values.)

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


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