Opened 10 years ago

Last modified 8 years ago

#6824 reopened Bugs

warning: delete called on boost::error_info... that has virtual functions but non-virtual destructor

Reported by: Richard Powell <rmpowell77@…> Owned by: Emil Dotchevski
Milestone: To Be Determined Component: exception
Version: Boost 1.56.0 Severity: Problem
Keywords: Cc:

Description

When compiling boost 1.49.0 thread.hpp with clang with -Wall, I receive warnings:

/Users/richardpowell/boost/include/boost/checked_delete.hpp:34:5: warning: delete called on

'boost::error_info<boost::tag_original_exception_type, const std::type_info *>' that has virtual functions but non-virtual destructor [-Wdelete-non-virtual-dtor]

delete x;

=-=-=

More details:

$ cat test2.cpp #include <boost/thread.hpp>

$ clang++ --version Apple clang version 4.0 (tags/Apple/clang-421.0.11) (based on LLVM 3.1svn) Target: x86_64-apple-darwin11.3.0 Thread model: posix

$ clang++ -g -I. -Wall -I ~/boost/include -c test2.cpp In file included from test2.cpp:1: In file included from /Users/richardpowell/boost/include/boost/thread.hpp:13: In file included from /Users/richardpowell/boost/include/boost/thread/thread.hpp:17: In file included from /Users/richardpowell/boost/include/boost/thread/pthread/thread_data.hpp:10: In file included from /Users/richardpowell/boost/include/boost/shared_ptr.hpp:17: In file included from /Users/richardpowell/boost/include/boost/smart_ptr/shared_ptr.hpp:30: /Users/richardpowell/boost/include/boost/checked_delete.hpp:34:5: warning: delete called on

'boost::error_info<boost::tag_original_exception_type, const std::type_info *>' that has virtual functions but non-virtual destructor [-Wdelete-non-virtual-dtor]

delete x;

/Users/richardpowell/boost/include/boost/smart_ptr/detail/shared_count.hpp:95:13: note: in instantiation of function template specialization

'boost::checked_delete<boost::error_info<boost::tag_original_exception_type, const std::type_info *> >' requested here

boost::checked_delete( p );

/Users/richardpowell/boost/include/boost/smart_ptr/shared_ptr.hpp:183:44: note: in instantiation of function template specialization

'boost::detail::shared_count::shared_count<boost::error_info<boost::tag_original_exception_type, const std::type_info *> >' requested here

explicit shared_ptr( Y * p ): px( p ), pn( p ) Y must be complete

/Users/richardpowell/boost/include/boost/exception/info.hpp:170:42: note: in instantiation of function template specialization

'boost::shared_ptr<boost::error_info<boost::tag_original_exception_type, const std::type_info *>

::shared_ptr<boost::error_info<boost::tag_original_exception_type, const std::type_info *> >' requested here

shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );

/Users/richardpowell/boost/include/boost/exception/info.hpp:191:16: note: in instantiation of function template specialization

'boost::exception_detail::set_info<boost::unknown_exception, boost::tag_original_exception_type, const std::type_info *>' requested here

return exception_detail::set_info(x,v);

/Users/richardpowell/boost/include/boost/exception/detail/exception_ptr.hpp:181:21: note: in instantiation of function template specialization

'boost::operator<<<boost::unknown_exception, boost::tag_original_exception_type, const std::type_info *>' requested here

(*this) << original_exception_type(&typeid(e));

/Users/richardpowell/boost/include/boost/exception/detail/exception_ptr.hpp:160:13: note: in instantiation of function template specialization

'boost::unknown_exception::add_original_type<std::exception>' requested here

add_original_type(e);

1 warning generated.

Change History (17)

comment:1 by ph03@…, 10 years ago

I have exactly the same warning with

$clang -v clang version 3.2 (trunk) Target: x86_64-pc-linux-gnu Thread model: posix . Shouldn't be too hard to fix, am I wrong?

comment:2 by viboes, 10 years ago

Component: threadexception
Owner: changed from Anthony Williams to Emil Dotchevski

I think that this issue has been fixed on Boost.Exception.

comment:3 by anonymous, 10 years ago

#6873 is a dupe with a different compiler, it should be reassigned also.

comment:4 by anonymous, 10 years ago

this issue is fixed in 1.50 by adding "virtual" at error_info_impl.hpp:33, the same fix I used to make my production builds work, so of course I'm happy with it ;-).

this ticket and #6873 should be closed.

comment:5 by Braunne, 8 years ago

For some reason, this fix did not work on my boost 1.47. Any ideas?

comment:6 by Emil Dotchevski, 8 years ago

Which fix?

comment:7 by anonymous, 8 years ago

Making the error_info_base destructor virtual

comment:8 by anonymous, 8 years ago

I'm using GCC 4.8. and this is the warning I'm getting:

.../boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'safe::SetFeatureUseOp' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]

delete x;

comment:9 by Emil Dotchevski, 8 years ago

Resolution: invalid
Status: newclosed

What does safe::SetFeatureUseOp have to do with Boost?

comment:10 by anonymous, 8 years ago

I really appreciate your desire to help.

In file included from .../boost/smart_ptr/shared_ptr.hpp:30:0,
                 from .../boost/shared_ptr.hpp:17,
                 from safeFeatureKeyTests.cc:17:
.../boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = safe::SetFeatureUseOp]':
.../boost/smart_ptr/detail/shared_count.hpp:95:38:   required from 'boost::detail::shared_count::shared_count(Y*) [with Y = safe::SetFeatureUseOp]'
.../boost/smart_ptr/shared_ptr.hpp:183:50:   required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = safe::SetFeatureUseOp; T = safe::TestOperation]'
safeFeatureKeyTests.cc:452:9:   required from here
.../boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'safe::SetFeatureUseOp' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
     delete x;
     ^

comment:11 by anonymous, 8 years ago

Maybe I lack the required understanding to resolve that issue, but upon first inspection it did seem like a boost issue. Agree?

comment:12 by sppande@…, 8 years ago

did anybody found the resolution for the issue mentioned in the above comment. After resolving bunch of issues i am stuck with this one, although i am on latest version of boost 1_56. any advice/suggestion would be great help.

Thanks, Shail

comment:13 by sppande@…, 8 years ago

Resolution: invalid
Status: closedreopened

comment:14 by anonymous, 8 years ago

Version: Boost 1.49.0Boost 1.56.0

comment:15 by Emil Dotchevski, 8 years ago

The lack of virtual destructor is by design, however the warning should not be happening. May I have compiler version and exact command line please?

comment:16 by sppande@…, 8 years ago

i am using gcc 4.7.2 on centos 6.5 i am getting this error when (ironbee) make command compiles files using gcc.

command looks like below

g++ -DFAVE_CONFIG_H -I/opt/boost_1_56_0/include -g -02 -pthread -MT ee.o -MD -MP -MF .deps/ee.Tpo -c -o ee.o ee.cpp

not sure if this helps much. Thanks for your quick response.

in reply to:  10 comment:17 by Steven Watanabe, 8 years ago

Replying to anonymous:

I really appreciate your desire to help.

In file included from .../boost/smart_ptr/shared_ptr.hpp:30:0,
                 from .../boost/shared_ptr.hpp:17,
                 from safeFeatureKeyTests.cc:17:
.../boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = safe::SetFeatureUseOp]':
.../boost/smart_ptr/detail/shared_count.hpp:95:38:   required from 'boost::detail::shared_count::shared_count(Y*) [with Y = safe::SetFeatureUseOp]'
.../boost/smart_ptr/shared_ptr.hpp:183:50:   required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = safe::SetFeatureUseOp; T = safe::TestOperation]'
safeFeatureKeyTests.cc:452:9:   required from here
.../boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'safe::SetFeatureUseOp' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
     delete x;
     ^

This is not a Boost issue. The error message only appears inside Boost because boost::shared_ptr has to call delete. The class that is causing the warning is not related to Boost in any way.

Note: See TracTickets for help on using tickets.