Boost C++ Libraries: Ticket #4200: Virtual functions, non-virtual destructor https://svn.boost.org/trac10/ticket/4200 <p> Non-virtual destructor produces warnings, like: warning: `boost::error_info&lt;cm::ErrnoTag, int&gt;' has virtual functions but non-virtual destructor </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4200 Trac 1.4.3 klimkin@… Fri, 07 May 2010 22:03:32 GMT attachment set https://svn.boost.org/trac10/ticket/4200 https://svn.boost.org/trac10/ticket/4200 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_exception_warning.patch</span> </li> </ul> <p> Patch for error_info_impl.hpp </p> Ticket anonymous Sun, 09 May 2010 23:34:09 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4200#comment:1 https://svn.boost.org/trac10/ticket/4200#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I don't have GCC 4.3.2 installed, but with -Wall I don't see any warnings using GCC 4.4.1 with the latest trunk. Please provide exact command line and source code. </p> Ticket Jan Kundrát <jkt@…> Sat, 15 Jan 2011 12:02:03 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/4200#comment:2 https://svn.boost.org/trac10/ticket/4200#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">worksforme</span> </li> </ul> <p> With gcc, you have to build with -Weffc++ in order to see warnings about non-virtual destructors in base class. For the record, I'm gettting this warning when using boost::spirit::qi::grammar. </p> Ticket Emil Dotchevski Mon, 17 Jan 2011 01:33:57 GMT <link>https://svn.boost.org/trac10/ticket/4200#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:3</guid> <description> <p> GCC 4.5.0/MinGW with -Weffc++ fails to produce this warning for me. Please provide exact command line for a single cpp file in libs/exception/test which produces the warning. </p> </description> <category>Ticket</category> </item> <item> <author>federico.schwindt@…</author> <pubDate>Tue, 29 Mar 2011 11:34:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:4</guid> <description> <p> Try with -Wnon-virtual-dtor. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Sun, 10 Apr 2011 02:19:41 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4200#comment:5 https://svn.boost.org/trac10/ticket/4200#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I've tried with various command line options. I need *exact* compiler version and *exact* command line that shows the warning. </p> Ticket federico.schwindt@… Mon, 11 Apr 2011 20:57:59 GMT <link>https://svn.boost.org/trac10/ticket/4200#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:6</guid> <description> <p> I get the error compiling mongodb with gcc 4.2.1 as it uses -Wnon-virtual-dtor (which is also enabled if -Weffc++ is used as per gcc manpage). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 27 Jan 2012 16:06:17 GMT</pubDate> <title>status, version, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/4200#comment:7 https://svn.boost.org/trac10/ticket/4200#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">Boost 1.48.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">worksforme</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Can reproduce in 1.48.0 with: </p> <p> Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn) Target: x86_64-apple-darwin11.2.0 Thread model: posix </p> <p> I'm not smart enough to make a test case. </p> <p> The patch worked for me. </p> Ticket shartwell@… Fri, 09 Mar 2012 00:35:47 GMT <link>https://svn.boost.org/trac10/ticket/4200#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:8</guid> <description> <p> Here's a test case for gcc. Also applies to all versions of clang. </p> <pre class="wiki">$ cat nonvdtor.cpp #include &lt;string&gt; class error_info_base { public: virtual std::string tag_typeid_name() const = 0; virtual std::string value_as_string() const = 0; protected: ~error_info_base() throw() { } }; $ gcc -v -c -Wnon-virtual-dtor nonvdtor.cpp ... gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00) ... nonvdtor.cpp:5: warning: ‘class error_info_base’ has virtual functions but non-virtual destructor </pre><p> Declaring <code>~error_info_base()</code> virtual will avoid the warning and allow our sources to include boost headers without having to suppress this warning in our own code. </p> <p> -- Steve Hartwell </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Fri, 09 Mar 2012 02:03:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:9</guid> <description> <p> Maybe I'm missing something, but I get no warnings running the Boost Exception tests with the command line: </p> <pre class="wiki">bjam variant=debug toolset=gcc cxxflags=-Wnon-virtual-dtor </pre><p> Same if I use: </p> <pre class="wiki">bjam variant=debug toolset=gcc cxxflags=-Weffc++ </pre><p> Also, here's my compiler version: </p> <pre class="wiki">$ g++ --version g++.exe (GCC) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </pre><p> Is there any reason why you pulled the code out from the Boost Exception header rather than just including it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mathias Gaunard</dc:creator> <pubDate>Fri, 13 Apr 2012 14:27:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:10</guid> <description> <p> I am getting tons of related errors, some of which come from using exception_ptr (which uses shared_ptr and checked_delete under the hood) to transfer exceptions between threads. </p> <p> warning: deleting object of polymorphic class type `boost::error_info&lt;boost::tag_original_exception_type, const std::type_info*&gt;' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]. </p> <p> This happens with -Wall on GCC 4.7. </p> <p> The fix is trivial, please just include it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Fri, 13 Apr 2012 19:01:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:11</guid> <description> <p> I just tried the following command line with GCC 4.7 on Windows: </p> <pre class="wiki">....\trunk\libs\exception\test&gt;g++ -c -I../../.. -Wall error_info_test.cpp </pre><p> The above command does not generate any console output. </p> <p> My GCC version: </p> <pre class="wiki">....\trunk\libs\exception\test&gt;g++ --version g++ (GCC) 4.7.0 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </pre><p> I do want to prevent this warning, but I still need help reproducing it. </p> </description> <category>Ticket</category> </item> <item> <author>zeratul976@…</author> <pubDate>Thu, 26 Apr 2012 22:58:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:12</guid> <description> <p> Emil, rather than compiling error_info_test.cpp, make a new file "test.cpp" in the same directory, with the following line as its content: </p> <p> #include &lt;boost/thread/future.hpp&gt; </p> <p> and try to compile it with the same options. You will now see the warning. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 29 May 2012 02:53:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:13</guid> <description> <p> source code(a.cc): </p> <pre class="wiki">#include &lt;boost/exception/all.hpp&gt; typedef boost::error_info&lt;struct my_info_tag, int&gt; my_info; int main() { my_info(0); } </pre><p> compiler: gcc-3.4.6 </p> <p> command line: g++ -Wall a.cc </p> <p> compiler output: </p> <pre class="wiki">/usr/local/include/boost/exception/detail/error_info_impl.hpp: In instantiation of `boost::error_info&lt;my_info_tag, int&gt;': a.cc:7: instantiated from here /usr/local/include/boost/exception/detail/error_info_impl.hpp:43: warning: `class boost::error_info&lt;my_info_tag, int&gt;' has virtual functions but non-virtual destructor </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Dean Michael Berris</dc:creator> <pubDate>Wed, 07 Nov 2012 03:58:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:14</guid> <description> <p> Any update on this? Can we please just merge this and be done with it? </p> </description> <category>Ticket</category> </item> <item> <author>persgray@…</author> <pubDate>Sun, 17 Mar 2013 15:30:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:15</guid> <description> <p> FWIW, the "virtual" modificator was removed in that commit: </p> <blockquote class="citation"> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/58072" title="Suppressing warnings. Please report any problems (may have broken ...">r58072</a> | emildotchevski | 2009-12-01 05:16:50 +0300 (Tue, 01 Dec 2009) | 1 line </p> <p> Suppressing warnings. Please report any problems (may have broken something!) </p> </blockquote> <p> So this really broke all software using boost and -Werror. Emil, what's were the warnings that <a class="changeset" href="https://svn.boost.org/trac10/changeset/58072" title="Suppressing warnings. Please report any problems (may have broken ...">r58072</a> should be fixing? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Sun, 17 Mar 2013 19:07:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:16</guid> <description> <p> The commit you mention is from 4 years ago. As far as I can tell virtual is present currently. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 04 Apr 2013 03:57:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4200#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4200#comment:17</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4200#comment:16" title="Comment 16">emildotchevski</a>: </p> <blockquote class="citation"> <p> The commit you mention is from 4 years ago. As far as I can tell virtual is present currently. </p> </blockquote> <p> Emil please, close this ticket and the other related to this warning if you have fixed them. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Thu, 04 Apr 2013 04:14:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4200#comment:18 https://svn.boost.org/trac10/ticket/4200#comment:18 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket