Home Dashboard Directory Help
Search

C4673 Compiling Exception Hierarchy Using Virtual Multiple Inheritence by John Dibling


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 690955
Opened: 9/26/2011 1:24:08 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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
{
public:
    MyException(const std::string& error) : error_(error) {};
private:
    std::string error_;
};

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

template<class EX> class TracedException : virtual protected std::exception, virtual public EX
{
public:
    TracedException(const std::string& file, int line, const EX& ex) : EX(ex), file_(file), line_(line) {};
private:
    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()
{
    try
    {
        throwx(MyException("Oh, Darn."));
    }
    catch( const MyException& ex )
    {
        ex;
    }
    catch( const My2ndException& ex2 )
    {
        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.
Details
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 MS-Moderator09 [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)
Sign in to post a workaround.