From aef3da86899c5f2cd4eed728b63bd82413106a43 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 11 Sep 2006 18:56:58 +0000 Subject: [PATCH 1/1] * data/glr.c (b4_shared_declarations): Put start-header first, before any #includes that we generate, so that feature-test macros work. Problem reported by Michael Deutschmann in . * data/lalr1.cc: Likewise. * doc/bison.texinfo (Prologue): Document that feature-test macros should be defined before any Bison declarations. * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Put defns that depend on location.hh after, not before, Bison decls, since we now include location.hh after the first user prologue. --- ChangeLog | 18 ++++++++++++++++++ data/glr.cc | 8 ++++---- data/lalr1.cc | 11 +++++------ doc/bison.texinfo | 8 ++++++++ tests/actions.at | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index dde03052..16802bb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,27 @@ 2006-09-11 Paul Eggert + * data/glr.c (b4_shared_declarations): Put start-header first, + before any #includes that we generate, so that feature-test + macros work. Problem reported by Michael Deutschmann in + . + * data/lalr1.cc: Likewise. + * doc/bison.texinfo (Prologue): Document that feature-test macros + should be defined before any Bison declarations. + * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Put defns + that depend on location.hh after, not before, Bison decls, since + we now include location.hh after the first user prologue. + * doc/bison.texinfo (Calc++ Parser): Fix memory leak reported by Sander Brandenburg in . Also, fix minor white space and comment issues. + (Prologue): Mention that it's better to define feature-test macros + before Bison declarations. Problem reported by Michael Deutschmann. + + * README-cvs: Fix typo: "&" should be "&&". Problem reported + by Jim Meyering. + * m4/.cvsignore: Add argmatch.m4. Remove obstack.m4, strerror_r.m4. + This adjusts to recent gnulib changes. 2006-09-04 Joel E. Denny diff --git a/data/glr.cc b/data/glr.cc index 59b9e3dd..a3cafe8e 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -221,6 +221,10 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++], #ifndef PARSER_HEADER_H # define PARSER_HEADER_H +]m4_ifdef([b4_start_header], +[[/* Copy the %start-header blocks. */ +]b4_user_start_header])[ + #include #include @@ -233,10 +237,6 @@ namespace ]b4_namespace[ class location; } -]m4_ifdef([b4_start_header], -[[/* Copy the %start-header blocks. */ -]b4_user_start_header])[ - #include "location.hh" /* Enabling traces. */ diff --git a/data/lalr1.cc b/data/lalr1.cc index 377659e5..73734281 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -43,6 +43,10 @@ dnl FIXME: This is wrong, we want computed header guards. #ifndef PARSER_HEADER_H # define PARSER_HEADER_H +]m4_ifdef([b4_start_header], +[[/* Copy the %start-header blocks. */ +]b4_user_start_header])[ + #include #include #include "stack.hh" @@ -53,12 +57,7 @@ namespace ]b4_namespace[ class location; } -]m4_ifdef([b4_start_header], -[[/* Copy the %start-header blocks. */ -]b4_user_start_header])[ - -]dnl Include location.hh here: it might depend on headers included above. -[#include "location.hh" +#include "location.hh" /* Enabling traces. */ #ifndef YYDEBUG diff --git a/doc/bison.texinfo b/doc/bison.texinfo index cf95066a..013847b5 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -2649,6 +2649,7 @@ can be done with two @var{Prologue} blocks, one before and one after the @smallexample %@{ + #define _GNU_SOURCE #include #include "ptypes.h" %@} @@ -2666,6 +2667,13 @@ can be done with two @var{Prologue} blocks, one before and one after the @dots{} @end smallexample +When in doubt, it is usually safer to put prologue code before all +Bison declarations, rather than after. For example, any definitions +of feature test macros like @code{_GNU_SOURCE} or +@code{_POSIX_C_SOURCE} should appear before all Bison declarations, as +feature test macros can affect the behavior of Bison-generated +@code{#include} directives. + @findex %before-header @findex %start-header @findex %after-header diff --git a/tests/actions.at b/tests/actions.at index e1b2cb99..6f52b069 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -190,7 +190,7 @@ m4_ifval([$6], [%union int ival; }]) AT_LALR1_CC_IF([%define "global_tokens_and_yystype"]) -m4_ifval([$6], [[%end-header {]], [[%start-header {]]) +m4_ifval([$6], [[%end-header {]], [[%after-header {]]) AT_LALR1_CC_IF([typedef yy::location YYLTYPE; m4_ifval([$6], , [#define YYSTYPE int])]) [static int yylex (]AT_LEX_FORMALS[); -- 2.45.2