Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get better information for the context of an error when using msvc? (ex: C2248)

I'm wondering if there is a way to get better information about the location of an error in msvc (2005)?

For example, when inheriting from boost::noncopyable in my class I get a C2248 error saying something like:

error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'. This diagnostic occurred in the compiler generated function 'MyClass::MyClass(const MyClass &)'

but it fail to tell me where exactly the copy constructor was called. This is a little annoying. I'm really not sure but I think I remember seeing a settings somewhere where I could specify the output level or something but I searched and found nothing so my question is: Is there a way to get better (fuller?) error message in msvc?

Edit: Well since stackoverflow just told me I should look to accept an answer, I was wondering if anyone could tell if msvc 2008/2010 give a better diagnostic for this error? Someone also mentioned GCC should do, can anyone confirm this? What about other compilers (Intel?, Comeau?)

Thanks

like image 887
n1ckp Avatar asked Oct 15 '09 19:10

n1ckp


1 Answers

I can confirm with Code::Blocks and VC++ 2005, that it gives no hint where the error occurs. Neither does declaring your own private copy constructor help.

#include <boost/noncopyable.hpp>

class X: boost::noncopyable
{
};

void foo(X x) {}

int main()
{

    X x;
    foo(x);
}

The compile log (line five is the last line of the class declaration):

main.cpp(5) : error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable' C:\boost_1_38_0\boost/noncopyable.hpp(27) : see declaration of 'boost::noncopyable_::noncopyable::noncopyable' C:\boost_1_38_0\boost/noncopyable.hpp(22) : see declaration of 'boost::noncopyable_::noncopyable' This diagnostic occurred in the compiler generated function 'X::X(const X &)'

Unless there's a compiler switch to enable more thorough error diagnostics, this wouldn't be the first time for me to simply compile the file with GCC (MinGW) to get more helpful error diagnostics. (Alas, your code should be free of VC++ extensions.)

like image 57
UncleBens Avatar answered Sep 27 '22 23:09

UncleBens