C4673 Compiling Exception Hierarchy Using Virtual Multiple Inheritence - by John Dibling

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 690955 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/26/2011 1:24:08 PM
Access Restriction Public


MSVC 10 and MSVC 9 are both generating a level 4 warning message when compiling my exception framework, although the behavior of the program seems correct. The exception framework is rather large & complex, but I have managed to boil it down to its essence. This is a complete program you can compile & run in VS10.

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdexcept>
using namespace std;

class MyException : virtual public std::exception
	MyException(const std::string& error) : error_(error) {};
	std::string error_;

class My2ndException : virtual public std::exception
	My2ndException(int n) : n_(n) {};
	int n_;

template<class EX> class TracedException : virtual protected std::exception, virtual public EX
	TracedException(const std::string& file, int line, const EX& ex) : EX(ex), file_(file), line_(line) {};
	std::string file_;
	int			line_;

template<class EX> TracedException<EX> make_traced_exception(const std::string& file, int line, const EX& ex)
	return TracedException<EX>(file, line, ex);

#define throwx(EX) (throw make_traced_exception(__FILE__, __LINE__, EX))

int main()
		throwx(MyException("Oh, Darn."));
	catch( const MyException& ex )
	catch( const My2ndException& ex2 )

When compiling the line:

throwx(MyException("Oh, Darn."));

...the compiler emits:

1>  main.cpp
1>main.cpp(43): warning C4673: throwing 'TracedException<EX>' the following types will not be considered at the catch site
1>          with
1>          [
1>              EX=MyException
1>          ]

By my reading of the C++ Standard, my code is well-formed and correct.  In addition, the code seems to function correctly when  execute it.  The error messages says there are incompatible types, but it fails to list those incompatible types even though it promises to list them.

There is a knowledge base article about this (ahttp://msdn.microsoft.com/en-us/library/32y577d8.aspx) but the suggested resolution -- to not throw the exception -- is completely unacceptable.

I also do not want to disable the warning via a pragma, as this code will be in an #include library.
Sign in to post a comment.
Posted by Microsoft on 10/14/2011 at 2:59 PM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by EricLeong [Feedback Moderator] on 9/26/2011 at 10:15 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 9/26/2011 at 6:46 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)