. <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <[EMAIL PROTECTED]> Cc: bug-bison@gnu.org Content-Transfer-Encoding: 7bit From: Hans Aberg <[EMAIL PROTECTED]> Subject: Re: too many warnings from Bison CVS for Pike Date: Thu, 9 Feb 2006 19:45:44 +0100 To: Paul Eggert <[EMAIL PROTECTED]> X-Mailer: Apple Mail (2.746.2)
On 9 Feb 2006, at 01:48, Paul Eggert wrote: > If a compiler defines __cplusplus, then yacc.c by default never calls > memcpy, so there should never be a correctness issue about bypassing > user-defined C++ assignment operators. There is a way to override > this, but it's not documented and nobody should use it unless they > really know what they're doing, and (again) it's on them to get it to > work. For details, please see data/yacc.c; for an example, see > src/parse-gram.c. I can give three C++ possibilities: Static C-parserstack. This seems what Bison is implementing for C++, i.e., yyoverflow is not defined, leaving up to the user to implement parser stack extensions. This will work with all C++ types, as long as the parser stack does not overflows. Dynamic C-parserstack. This is what is Bison implements if __cplusplus is not defined. However, this should work under C++ as well for POD types. By the segment: #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { short int yyss; YYSTYPE yyvs; YYLTYPE yyls; }; ... you already have a test against non-POD types, as these cannot be used in a union. So if one would want to use this dynamic stack with a POD type, just remove the (! defined (__cplusplus) above. Dynamic C-parserstack with C++ extensions. This would be the same as the dynamic C-parserstack, but with some extra C++ extensions (using __cplusplus) so that also non-POD semantic types can be used, and possibly even with C++ exceptions. This was (I think) discussed before, somebody even posting examples how to call assignment operators and destructors explicitly. One might at this point also even provide proper cleanup using the %destructor implementation. But it seems quite complicated. But one might supply a macro, say CPP_SEMANTIC_POD, which signals that the C++ semantic type is a POD, and that the dynamic C- parserstack should be used. The code above would then look like (I think, if I cmoputed it right): #if (! defined (yyoverflow) \ && (! ((defined (__cplusplus) && !(defined CPP_SEMANTIC_POD))) \ || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \ && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) I.e., if __cplusplus is defined, and also CPP_SEMANTIC_POD, then yyoverflow should be defined as well. - Also, there is an error in the comment of the block right above: # if defined (__STDC__) || defined (__cplusplus) # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t I think this comment is due to the compiler I formerly used, which added a "using namespace std" in its C compatibility header. However, this is wrong according to the C++ standard: One just adds a new name for each name defined in the C-header. For example, the C++ of malloc is std::malloc, but when the C-compatibility header is added, one just gets the name ::malloc added. So this comment can simply be taken away. Hans Aberg