Reputation: 1521
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
Upvotes: 8
Views: 1771
Reputation: 1
Actually, the best way to workaround this (VS2013 here) seems to crawl over the output window iteratively:
1/ when you get the message "This diagnostic occurred in the compiler generated function 'X::X(const X &)'" in the output, go to your 'X' class and explicitly remove the copy constructor using the C++11 notation: "X(const X&) = delete;"
2/ recompile, now the output must display the same error but with a diagnostic occuring on child-classes, then loop again to the step 1 to explicitely delete the copy constructor on the child class, until you reach the real faulty class...
Upvotes: 0
Reputation: 41351
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.)
Upvotes: 4
Reputation: 99122
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
Upvotes: -1
Reputation: 14327
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.
Upvotes: -1
Reputation: 2743
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.
Upvotes: 0