bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -Wweak-vtables warnings (was: Bison 3.2.91 released [beta])


From: Akim Demaille
Subject: Re: -Wweak-vtables warnings (was: Bison 3.2.91 released [beta])
Date: Sun, 20 Jan 2019 08:49:45 +0100

Hi Derek!

> Le 19 janv. 2019 à 20:47, Derek Clegg <address@hidden> a écrit :
> 
> I ran into just one issue:
> 
> 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
>           ^
> 1 error generated.

I don't think I will address this warning, the cure is way worse than the 
problem.

To add the destructor, I must make the signature explicit, and it cannot be 
different from the one in the base class, so I must add noexcept:

   ~syntax_error () YY_NOEXCEPT;

but then I have errors because YY_NOEXCEPT does not map to `throw()` in C++98.  
If I "fix" it:

// Support noexcept when possible.
#if 201103L <= YY_CPLUSPLUS
# define YY_NOEXCEPT noexcept
#else
# define YY_NOEXCEPT throw ()
#endif

then I get many failures with Clang.  For instance test 323:

> 323. types.at:366: testing lalr1.cc api.value.type={double} ...
> ======== Testing with C++ standard flags: ''
> /Users/akim/src/gnu/bison/tests/types.at:366: bison -fno-caret  -o test.cc 
> test.y
> /Users/akim/src/gnu/bison/tests/types.at:366: $CXX $CXXFLAGS $CPPFLAGS  
> $LDFLAGS -o test test.cc $LIBS
> stderr:
> stdout:
> /Users/akim/src/gnu/bison/tests/types.at:366:  $PREPARSER ./test
> stderr:
> /Users/akim/src/gnu/bison/tests/types.at:366: sed >&2 -e 
> '/^profiling:.*:Merge mismatch for summaries/d' stderr
> ======== Testing with C++ standard flags: ''
> /Users/akim/src/gnu/bison/tests/types.at:366: bison -fno-caret  -o test.cc 
> test.y
> /Users/akim/src/gnu/bison/tests/types.at:366: $CXX $CXXFLAGS $CPPFLAGS  
> $LDFLAGS -o test test.cc $LIBS
> stderr:
> test.cc:245:12: error: exception specification is not available until end of 
> class definition
>       bool empty () const YY_NOEXCEPT;
>            ^
> test.cc:935:15: note: in instantiation of member function 
> 'yy::parser::basic_symbol<yy::parser::by_state>::empty' requested here
>     if (yysym.empty ())
>               ^
> test.cc:948:7: note: in instantiation of function template specialization 
> 'yy::parser::yy_print_<yy::parser::by_state>' requested here
>       YY_SYMBOL_PRINT (m, sym);
>       ^
> test.cc:708:7: note: expanded from macro 'YY_SYMBOL_PRINT'
>       yy_print_ (*yycdebug_, Symbol);           \
>       ^
> test.cc:549:7: error: exception specification is not available until end of 
> class definition
>       pop (int n = 1) YY_NOEXCEPT
>       ^
> test.cc:966:14: note: in instantiation of member function 
> 'yy::parser::stack<yy::parser::stack_symbol_type, 
> std::__1::vector<yy::parser::stack_symbol_type, 
> std::__1::allocator<yy::parser::stack_symbol_type> > >::pop' requested here
>     yystack_.pop (n);
>              ^
> test.cc:557:7: error: exception specification is not available until end of 
> class definition
>       clear () YY_NOEXCEPT
>       ^
> test.cc:1053:14: note: in instantiation of member function 
> 'yy::parser::stack<yy::parser::stack_symbol_type, 
> std::__1::vector<yy::parser::stack_symbol_type, 
> std::__1::allocator<yy::parser::stack_symbol_type> > >::clear' requested here
>     yystack_.clear ();
>              ^
> test.cc:245:12: error: exception specification is not available until end of 
> class definition
>       bool empty () const YY_NOEXCEPT;
>            ^
> test.cc:1079:14: note: in instantiation of member function 
> 'yy::parser::basic_symbol<yy::parser::by_type>::empty' requested here
>     if (yyla.empty ())
>              ^
> test.cc:564:7: error: exception specification is not available until end of 
> class definition
>       size () const YY_NOEXCEPT
>       ^
> test.cc:1262:24: note: in instantiation of member function 
> 'yy::parser::stack<yy::parser::stack_symbol_type, 
> std::__1::vector<yy::parser::stack_symbol_type, 
> std::__1::allocator<yy::parser::stack_symbol_type> > >::size' requested here
>           if (yystack_.size () == 1)
>                        ^
> test.cc:571:7: error: exception specification is not available until end of 
> class definition
>       begin () const YY_NOEXCEPT
>       ^
> test.cc:1426:25: note: in instantiation of member function 
> 'yy::parser::stack<yy::parser::stack_symbol_type, 
> std::__1::vector<yy::parser::stack_symbol_type, 
> std::__1::allocator<yy::parser::stack_symbol_type> > >::begin' requested here
>            i = yystack_.begin (),
>                         ^
> test.cc:578:7: error: exception specification is not available until end of 
> class definition
>       end () const YY_NOEXCEPT
>       ^
> test.cc:1427:29: note: in instantiation of member function 
> 'yy::parser::stack<yy::parser::stack_symbol_type, 
> std::__1::vector<yy::parser::stack_symbol_type, 
> std::__1::allocator<yy::parser::stack_symbol_type> > >::end' requested here
>            i_end = yystack_.end ();
>                             ^
> 7 errors generated.
> stdout:
> /Users/akim/src/gnu/bison/tests/types.at:366: exit code was 1, expected 0
> 323. types.at:366: 323. lalr1.cc api.value.type={double} (types.at:366): 
> FAILED (types.at:366)

The message is somewhat unclear (exception specification is not available until 
end of class definition), and it seems to be a bug in Clang 
(https://stackoverflow.com/questions/48340412/ but it's not exactly the same 
case).

I have spent some time trying to work around this, to no avail.

The warning itself is completely harmless.  Unless you find a workaround for 
the clang error, I will leave this as is.  You can start from this branch: 
https://github.com/akimd/bison/tree/Wweak-vtables, which corresponds to this:

commit 1d66cbc33f1f07c976d0953a91709bf8df290ccf
Author: Akim Demaille <address@hidden>
Date:   Sun Jan 20 08:23:41 2019 +0100

    wip

diff --git a/configure.ac b/configure.ac
index a3a471af..1b5343e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,7 +100,7 @@ if test "$enable_gcc_warnings" = yes; then
     -Wpointer-arith -Wshadow
     -Wwrite-strings'
   warn_c='-Wbad-function-cast -Wstrict-prototypes'
-  warn_cxx='-Wextra-semi -Wnoexcept -Wundefined-func-template'
+  warn_cxx='-Wextra-semi -Wnoexcept -Wundefined-func-template -Wweak-vtables'
   # Warnings for the test suite only.
   #
   # -fno-color-diagnostics: Clang's use of colors in the error
diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4
index e682ada4..f5d21ce9 100644
--- a/data/skeletons/c++.m4
+++ b/data/skeletons/c++.m4
@@ -78,7 +78,7 @@ m4_define([b4_cxx_portability],
 #if 201103L <= YY_CPLUSPLUS
 # define YY_NOEXCEPT noexcept
 #else
-# define YY_NOEXCEPT
+# define YY_NOEXCEPT throw ()
 #endif[]dnl
 
 // Support noexcept when possible.
@@ -217,7 +217,14 @@ m4_define([b4_public_types_declare],
       syntax_error (]b4_locations_if([const location_type& l, ])[const 
std::string& m)
         : std::runtime_error (m)]b4_locations_if([
         , location (l)])[
-      {}]b4_locations_if([
+      {}
+
+      syntax_error (const syntax_error& s)
+        : std::runtime_error (s.what ())]b4_locations_if([
+        , location (s.location)])[
+      {}
+
+      ~syntax_error () YY_NOEXCEPT;]b4_locations_if([
 
       location_type location;])[
     };
diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc
index 7d333bf2..414bed1e 100644
--- a/data/skeletons/glr.cc
+++ b/data/skeletons/glr.cc
@@ -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
+  {}
+
   int
   ]b4_parser_class[::operator() ()
   {
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 053ba3be..4743287a 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -562,6 +562,9 @@ m4_if(b4_prefix, [yy], [],
   ]b4_parser_class::~b4_parser_class[ ()
   {}
 
+  ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT
+  {}
+
 
   /*---------------.
   | Symbol types.  |


Cheers!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]