Opened 8 years ago

Last modified 8 years ago

#10462 new Bugs

throw exception inherits two std::exception

Reported by: gilles.guerre-chaley@… Owned by: Emil Dotchevski
Milestone: To Be Determined Component: exception
Version: Boost 1.56.0 Severity: Optimization
Keywords: visual studio 2013 x64 Cc:

Description

// example
  class my_exception: public std::exception { };
  try  {
     boost::throw_exception(my_exception());   
  } catch(  my_exception & e)
  {...  }

Inheritance of e

-> ... clone_impl<boost::exception_detail::error_info_injector<my_exception> >	
-> ->		my_exception
-> ->  ->		std::exception		
...
->		std::exception

Change History (4)

comment:1 by Emil Dotchevski, 8 years ago

Is it possible that my_exception derives from std::exception privately?

There are checks which should fail with ambiguous implicit conversion errors in case std::exception is derived from multiple times. I'm noticing, however, that the relevant unit test throw_exception_test.cpp doesn't explicitly verify this.

Could you help me diagnose the error? Insert the following snipped into throw_exception_test.cpp, run it, and let me know if it fails for you. It works on my darwin build (the idea of this insertion is that if std::exception is derived from multiple times, the catch(std::exception&) would fail since the conversion would be ambiguous.)

@@ -76,7 +76,21 @@ throw_fwd( void (*thrower)(int) )
     {
     try
         {
-        thrower(42);
+        try
+            {
+            thrower(42);
+            }
+        catch(
+        std::exception & )
+            {
+            throw;
+            }
+        catch(
+        ... )
+            {
+            BOOST_ERROR("throw_fwd failed to catch std::exception, possibly because it was derived from multiply.");
+            throw;
+            }
         }
     catch(
     boost::exception & x )

Thanks, Emil

Last edited 8 years ago by Emil Dotchevski (previous) (diff)

comment:2 by gregory.boero-teyssier@…, 8 years ago

hello the file you're named throw_exception_test.cpp doesn't compile with or without your modification

list of error :

Erreur	4	error LNK1120: 3 externes non rΘsolus Visual Studio 2013\Projects\ggcTestBoost\x64\Debug\ggcTestBoost.exe	ggcTestBoost
Erreur	2	error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception<struct boost::exception_test::derives_boost_exception_virtually>(int)" (??$throw_test_exception@Uderives_boost_exception_virtually@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester<struct boost::exception_test::derives_boost_exception_virtually>(void)" (??$tester@Uderives_boost_exception_virtually@exception_test@boost@@@@YAXXZ)	C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj	ggcTestBoost
Erreur	1	error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception<struct boost::exception_test::derives_boost_exception>(int)" (??$throw_test_exception@Uderives_boost_exception@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester<struct boost::exception_test::derives_boost_exception>(void)" (??$tester@Uderives_boost_exception@exception_test@boost@@@@YAXXZ)	C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj	ggcTestBoost
Erreur	3	error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception<struct boost::exception_test::derives_std_exception>(int)" (??$throw_test_exception@Uderives_std_exception@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester<struct boost::exception_test::derives_std_exception>(void)" (??$tester@Uderives_std_exception@exception_test@boost@@@@YAXXZ)	C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj	ggcTestBoost

comment:3 by Emil Dotchevski, 8 years ago

You mean it doesn't link. You need to link helper2.cpp or run boost build, the Jamfile in that directory works.

comment:4 by gregory.boero-teyssier@…, 8 years ago

yes sure it won't work like this, i haven't seen the

#include "helper2.hpp"

in the file. Sorry i'm new in c++ world but even now it's not working

Erreur	1	error C2039: 'throw_function_' : n'est pas membre de 'exception1'	
Erreur	2	error C2039: 'throw_file_' : n'est pas membre de 'exception1'	
Erreur	3	error C2039: 'throw_line_' : n'est pas membre de 'exception1'	

Let me know if i forgot to do something.

Thanks, grégory

Note: See TracTickets for help on using tickets.