views:

196

answers:

5

Hi,

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

Exemple, 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

A: 

In the output window or the build log you should see where the compiler tried to use the template in your code... you have to scroll around a bit though.

If there is not enough information in the build logs, there is also an option controlling msbuild verbosity:
Tools->Options->Projects and Solutions->Build and Run->MSBuild project output verbosity

Georg Fritzsche
Thanks. This was exactly the options I was thinking about. I will try to see if it give more info and report back. Thanks.
n1ck
I tried, sadly it doesn't help - see UncleBens answer.
Georg Fritzsche
A: 

You could temporarily create a manual copy constructor (with the same signature) and the default implementation, just for the purpose of tracking down this error..? Not sure if that would make it any easier to find.

sean riley
My question is not related to this particular error. My current error is not related to a copy constructor. That was an example. Still, thanks for answering.
n1ck
A: 

Open the output window, where the full building log is displayed. Check there the error message. Under that error message, you can usually find more information that can help you trace the source of the problem.

If you double click the problem in the error list and the go to the output window, the cursor will be positioned to that error message.

Cătălin Pitiș
Hmm I knew I should have copy/pasted the full string so you don't think I got this from the error windows. I got this from the output windows and the only reference I got to find the error is the .cpp file where the error occured but I would like to know the location of the call to the copy constructor or any more info I can get. Thanks anyway.
n1ck
With templates you usually have to scroll down past some 'noise' to get to the part where your source is mentioned.
Georg Fritzsche
+2  A: 

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.)

UncleBens
Didn't remember that one. At least one can guess rather quick what the problem is with noncopyable.
Georg Fritzsche
The problem is not with noncopyable. The problem is with *your* code trying to copy something that it shouldn't be copying.
UncleBens
Thats what i meant. When using noncopyable you can at least figure out quickly what it means, unlike with other use-cases. There is also no useful cl.exe switch that sheds more light on this.
Georg Fritzsche
Well that's sad for msvc, but i'll take a look to install GCC if I can't find another workaround for my problem just to see the error message there. Congrats, you tested the solution faster than I ;o). I'll wait a day or 2 to see if other answers come in but I checked compiler options for msvc and It don't look like there is an option for better error messages so I'll probably accept your answer. Thanks a lot!
n1ck
Of course, you could check for similar passing by value. Another thing: you don't attempt to store your noncopyable objects in a standard container?
UncleBens
Well in fact my problem isn't even related to the copy constructor (it's the same C2248 error though, something about attempting to access a private member) so no, but I think I will be able to solve it. Thanks for the help man.
n1ck
A: 

I've never tried to make it work inside of Visual Studio, but if you don't mind compiling from the command line, STLFilt, from Brain Damaged Software, can be quite helpful.

For those who've been around a while, and think BDS sounds a bit familiar, yes, this is the same company (or guy, really -- Leor Zolman) who wrote BDS C, one of the first C compilers for CP/M.

Edit: Looking at the site, it appears that filtering in the IDE does now work.

Jerry Coffin
Well it sure looks like it can be useful but I don't see how this is related to my question at all. If I read the site correctly it basically simplify long template error message so you can read them better. My question is about the inverse: How to get MORE info about an error because msvc doesn't give enough (for error C2248 at least). Anyway, I solved my problem so thanks anyway everyone.
n1ck
My guess, which I'll admit *might* have been wrong, was that the right data probably was in there, but it was getting lost in the morass. I've triggered errors like this all too often, and with enough looking, the right information *was* always there -- but it was hard to find the crucial bit in what was sometimes 200+ lines of error messages...
Jerry Coffin