Suppress some warnings caused by a Berkeley YACC bug/misfeature.

Berkeley YACC generates a global declaration of yylval, or the
appropriately prefixed version of yylval, in the .h file, *even though
it's been told to generate a pure parser, meaning it doesn't have any
global variables*.  Bison doesn't do this.

That causes a warning due to the local declaration in the parser
shadowing the global declaration.

So, if this is Berkeley YACC, and we have _Pragma, and have pragmas to
suppress diagnostics, we use it to turn off -Wshadow warnings.

Change-Id: Ia3fecd99fa18ca9b85f6b25f53ed36c60730fad9
Reviewed-on: https://code.wireshark.org/review/26080
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2018-02-24 03:52:23 -08:00
parent f07d295fcf
commit c0b2d82fc4
2 changed files with 35 additions and 0 deletions

View File

@ -148,12 +148,16 @@ XMIT-Max7:20: (task "_brouterControlTask" at 0xb094ac20, time: 1481.51) 20 octet
#include "ascendtext.h"
#include "ascend-int.h"
#include "ascend.h"
DIAG_OFF_BYACC
#include "ascend_scanner_lex.h"
DIAG_ON_BYACC
#include "file_wrappers.h"
#define NO_USER "<none>"
extern void yyerror (void *yyscanner, ascend_state_t *state, FILE_T fh _U_, const char *s);
DIAG_OFF_BYACC
%}
%union {
@ -429,6 +433,8 @@ datagroup: dataln
%%
DIAG_ON_BYACC
/* Run the parser. */
int
run_ascend_parser(FILE_T fh, wtap_rec *rec, guint8 *pd,

View File

@ -113,6 +113,13 @@ extern "C" {
__pragma(warning(disable:4244)) \
__pragma(warning(disable:4267))
#define DIAG_ON_FLEX __pragma(warning(pop))
/*
* XXX - is there an issue with shadowed definitions with MSVC if
* somebody were to happen to use Berkeley YACC rather than Bison?
*/
#define DIAG_OFF_BYACC
#define DIAG_ON_BYACC
#else
/*
* Suppress:
@ -145,6 +152,28 @@ extern "C" {
#define DIAG_ON_FLEX \
DIAG_ON(sign-compare)
#endif
/*
* Berkeley YACC generates a global declaration of yylval, or the
* appropriately prefixed version of yylval, in grammar.h, *even
* though it's been told to generate a pure parser, meaning it
* doesn't have any global variables*. Bison doesn't do this.
*
* That causes a warning due to the local declaration in the parser
* shadowing the global declaration.
*
* So, if this is Berkeley YACC, and we have _Pragma, and have pragmas
* to suppress diagnostics, we use it to turn off -Wshadow warnings.
*/
#ifdef YYBYACC
#define DIAG_OFF_BYACC \
DIAG_OFF(shadow)
#define DIAG_ON_BYACC \
DIAG_ON(SHADOW)
#else
#define DIAG_OFF_BYACC
#define DIAG_ON_BYACC
#endif
#endif
/*