help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %union with STL


From: Vincent Zweije
Subject: Re: %union with STL
Date: Wed, 27 May 2009 10:32:20 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

On Tue, May 26, 2009 at 10:57:01PM +0200, Hans Aberg wrote:

||  On 26 May 2009, at 22:38, Luca wrote:
||
||  >> Checking what the compiler accepts is a good way to produce non-
||  >> standard source code
||  > using a pointer inside a union is a good way to produce non-standard
||  > source code?!?
||
||  So what does the C++ standard say about it?

"In a union, at most one of the data members can be active at any time,
that is, the value of at most one of the data members can be stored in
a union at any time. [...] Each data member is allocated as if it were
the sole member of a struct."

And for those interested in the problem with the bison union:

"An object of a class with a non-trivial constructor (12.1), a non-trivial
copy construtor (12.8), a non-trivial destructor (12.4), or a non-trivial
copy assignment operator (13.5.3, 12.8) cannot be a member of a union,
nor can an array of such objects."

The rationale being that when default-constructing, copy-constructing,
destroying, or assigning the union, the program doesn't have to know which
member to use, because under these rules it can just operate on the data.

In short, I see no problem with this union at all as bison uses it,
semantics-wise, but it is unfortunate that you cannot put your own
classes in there in general.

||  >> But in the end, I think the OP problem might be due to an older
||  >> version of Bison or an instantiation problem - lack of declaration
||  >> or a problem with the compiler.
||  > Simply some #include is missing...
||
||  Did you see the post by Vincent?

And I noticed that std::string appears to be used as well, which needs
a #include <string>. :)

Ciao.                                                             Vincent.
-- 
WCC - Smart Search & Match
NL  +31 30 7503222
address@hidden
www.wcc-group.com

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]