mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
c++: issue a compile-time warning when #define YYSTYPE is used
Using #define YYSTYPE has always been strongly discouraged in C++. Macros are dangerous and can result in subtle bugs. https://lists.gnu.org/r/bug-bison/2020-12/msg00007.html Maybe some people are currently using #define YYSTYPE. Instead of dropping support right now, first issue a warning. Bison can "see" if YYDEBUG is defined (it could even be on the command line), only the compiler knows. Unfortunately `#warning` is non-portable, and actually GCC even dies on it when `-pedantic` is enabled. So we need to use `#pragma message`. We must make it conditional as some compilers might not support it, but it doesn't matter if only _some_ compilers emit the warning: it should be enough to catch the attention of the developers. * data/skeletons/c++.m4: Issue a warning when the user defined YYSTYPE. * tests/actions.at: Don't #define YYSTYPE. * tests/headers.at (Several parsers): Ignore the YYSTYPE in the warning.
This commit is contained in:
@@ -1777,8 +1777,6 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
float fval;
|
||||
} sem_type;
|
||||
|
||||
# define YYSTYPE sem_type
|
||||
|
||||
]AT_CXX_IF([[
|
||||
# include <cstdio> // EOF.
|
||||
# include <iostream>
|
||||
@@ -1800,6 +1798,8 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
]])[
|
||||
}
|
||||
|
||||
%define api.value.type {sem_type}
|
||||
|
||||
%code
|
||||
{
|
||||
]AT_YYERROR_DECLARE[
|
||||
|
||||
Reference in New Issue
Block a user