bison: allow trivially copyable C++ YYLTYPE

Problem reported by James K. Lowden in:
https://lists.gnu.org/r/bison-patches/2026-07/msg00000.html
* data/skeletons/yacc.c: In C++, check that YYLTYPE is
trivially copyable if this is not already known.
But skip the check in older compilers.
This commit is contained in:
Paul Eggert
2026-07-21 12:52:53 -07:00
parent 3841fe9de4
commit 089c39aab2
2 changed files with 24 additions and 4 deletions
+3
View File
@@ -8,6 +8,9 @@ GNU Bison NEWS
The C++ skeletons now expose copy and move operators for symbols.
The default (C) skeleton now supports user-defined semantic and location
types that are trivially copyable in C++.
Fixed portability issues of the test suite on Solaris.
Fixed spurious warnings about input containing `m4_` or `b4_`.
+21 -4
View File
@@ -581,10 +581,27 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
# define YYCOPY_NEEDED 1]])[
#endif /* ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
&& ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL)))
#ifndef yyoverflow
/* In C++, ]b4_api_PREFIX[STYPE must be trivially copyable.
If ]b4_api_PREFIX[STYPE_IS_TRIVIAL, this is already known.
Otherwise check this if easy, as in newer C++ compilers.]b4_locations_if([[
Likewise for ]b4_api_PREFIX[LTYPE.]])[ */
# if (! (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
&& ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL) \
&& defined __cplusplus && 201103 <= __cplusplus \
&& !(defined _GLIBCXX_RELEASE \
? _GLIBCXX_RELEASE < 5 \
: defined __GLIBCXX__) \
&& defined __has_include)
# if __has_include (<type_traits>)
# include <type_traits>
]b4_locations_if(
[[static_assert (std::is_trivially_copyable<]b4_api_PREFIX[LTYPE>::value,
"Bison error: api.location.type is not trivially copyable");
]])[static_assert (std::is_trivially_copyable<]b4_api_PREFIX[STYPE>::value,
"Bison error: api.value.type is not trivially copyable");
# endif
# endif
/* A type that is properly aligned for any stack member. */
union yyalloc