c++: address -Wweak-vtables warnings

Reported by Derek Clegg
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00021.html

    aux/parser-internal.h:429:12: error: 'syntax_error' has no out-of-line virtual
         method definitions; its vtable will be emitted in every translation unit
         [-Werror,-Wweak-vtables]
       struct syntax_error : std::runtime_error

To avoid this warning, we need syntax_error to have a virtual function
defined in a compilation unit.  Let it be the destructor.  To comply
with C++98, this dtor should be 'throw()'.  Merely making YY_NOEXCEPT
be 'throw()' in C++98 triggers
errors (http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00022.html),
so let's introduce YY_NOTHROW and flag only ~syntax_error with it.

Also, since we now have an explicit dtor, we need to provide an copy
ctor.

* configure.ac (warn_cxx): Add -Wweak-vtables.
* data/skeletons/c++.m4 (YY_NOTHROW): New.
(syntax_error): Declare the dtor, and define the copy ctor.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc (~syntax_error):
Define.
This commit is contained in:
Akim Demaille
2019-01-20 08:23:41 +01:00
parent 05b70f47e8
commit ec08b369ec
5 changed files with 17 additions and 2 deletions

View File

@@ -160,6 +160,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
]b4_parser_class::~b4_parser_class[ ()
{}
]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW
{}
int
]b4_parser_class[::operator() ()
{