Modify

Ticket #4200 (closed Bugs: fixed)

Opened 4 years ago

Last modified 13 months ago

Virtual functions, non-virtual destructor

Reported by: klimkin@… Owned by: emildotchevski
Milestone: To Be Determined Component: exception
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc: GCC 4.3.2

Description

Non-virtual destructor produces warnings, like: warning: `boost::error_info<cm::ErrnoTag, int>' has virtual functions but non-virtual destructor

Attachments

boost_exception_warning.patch Download (407 bytes) - added by klimkin@… 4 years ago.
Patch for error_info_impl.hpp

Change History

Changed 4 years ago by klimkin@…

Patch for error_info_impl.hpp

comment:1 Changed 4 years ago by anonymous

  • Status changed from new to closed
  • Resolution set to worksforme

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.

comment:2 Changed 3 years ago by Jan Kundrát <jkt@…>

  • Status changed from closed to reopened
  • Resolution worksforme deleted

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.

comment:3 Changed 3 years ago by emildotchevski

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.

comment:4 Changed 3 years ago by federico.schwindt@…

Try with -Wnon-virtual-dtor.

comment:5 Changed 3 years ago by emildotchevski

  • Status changed from reopened to closed
  • Resolution set to worksforme

I've tried with various command line options. I need *exact* compiler version and *exact* command line that shows the warning.

comment:6 Changed 3 years ago by federico.schwindt@…

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).

comment:7 Changed 2 years ago by anonymous

  • Status changed from closed to reopened
  • Version changed from Boost 1.43.0 to Boost 1.48.0
  • Resolution worksforme deleted
  • Milestone changed from Boost 1.43.0 to To Be Determined

Can reproduce in 1.48.0 with:

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

I'm not smart enough to make a test case.

The patch worked for me.

comment:8 Changed 2 years ago by shartwell@…

Here's a test case for gcc. Also applies to all versions of clang.

$ cat nonvdtor.cpp 
#include <string>
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

Declaring ~error_info_base() virtual will avoid the warning and allow our sources to include boost headers without having to suppress this warning in our own code.

-- Steve Hartwell

comment:9 Changed 2 years ago by emildotchevski

Maybe I'm missing something, but I get no warnings running the Boost Exception tests with the command line:

bjam variant=debug toolset=gcc cxxflags=-Wnon-virtual-dtor

Same if I use:

bjam variant=debug toolset=gcc cxxflags=-Weffc++

Also, here's my compiler version:

$ 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.

Is there any reason why you pulled the code out from the Boost Exception header rather than just including it?

comment:10 Changed 2 years ago by mgaunard

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.

warning: deleting object of polymorphic class type `boost::error_info<boost::tag_original_exception_type, const std::type_info*>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor].

This happens with -Wall on GCC 4.7.

The fix is trivial, please just include it.

comment:11 Changed 2 years ago by emildotchevski

I just tried the following command line with GCC 4.7 on Windows:

....\trunk\libs\exception\test>g++ -c -I../../.. -Wall error_info_test.cpp

The above command does not generate any console output.

My GCC version:

....\trunk\libs\exception\test>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.

I do want to prevent this warning, but I still need help reproducing it.

comment:12 Changed 2 years ago by zeratul976@…

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:

#include <boost/thread/future.hpp>

and try to compile it with the same options. You will now see the warning.

comment:13 Changed 2 years ago by anonymous

source code(a.cc):

#include <boost/exception/all.hpp>

typedef boost::error_info<struct my_info_tag, int> my_info;

int main()
{
        my_info(0);
}

compiler: gcc-3.4.6

command line: g++ -Wall a.cc

compiler output:

/usr/local/include/boost/exception/detail/error_info_impl.hpp: In instantiation of `boost::error_info<my_info_tag, int>':
a.cc:7:   instantiated from here
/usr/local/include/boost/exception/detail/error_info_impl.hpp:43: warning: `class boost::error_info<my_info_tag, int>' has virtual functions but non-virtual destructor

comment:14 Changed 18 months ago by mikhailberis

Any update on this? Can we please just merge this and be done with it?

comment:15 Changed 13 months ago by persgray@…

FWIW, the "virtual" modificator was removed in that commit:

r58072 | emildotchevski | 2009-12-01 05:16:50 +0300 (Tue, 01 Dec 2009) | 1 line

Suppressing warnings. Please report any problems (may have broken something!)

So this really broke all software using boost and -Werror. Emil, what's were the warnings that r58072 should be fixing?

comment:16 follow-up: ↓ 17 Changed 13 months ago by emildotchevski

The commit you mention is from 4 years ago. As far as I can tell virtual is present currently.

comment:17 in reply to: ↑ 16 Changed 13 months ago by viboes

Replying to emildotchevski:

The commit you mention is from 4 years ago. As far as I can tell virtual is present currently.

Emil please, close this ticket and the other related to this warning if you have fixed them.

comment:18 Changed 13 months ago by emildotchevski

  • Status changed from reopened to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.