简体   繁体   English

使用msvc时是否有办法获取有关错误上下文的更好信息? (例如:C2248)

[英]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)? 我想知道是否有一种方法可以获取有关msvc(2005)中错误位置的更好信息?

For example, when inheriting from boost::noncopyable in my class I get a C2248 error saying something like: 例如,在类中从boost :: noncopyable继承时,出现C2248错误,内容如下:

error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'. 错误C2248:“ boost :: noncopyable _ :: noncopyable :: noncopyable”:无法访问在“ boost :: noncopyable _ :: noncopyable”类中声明的私有成员。 This diagnostic occurred in the compiler generated function 'MyClass::MyClass(const MyClass &)' 此诊断发生在编译器生成的函数'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? 我真的不确定,但是我想我记得在某个地方可以指定输出级别或其他设置,但是我搜索并没有发现任何设置,所以我的问题是:是否有一种方法可以使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? 编辑:好吧,因为stackoverflow只是告诉我我应该看一下接受答案,所以我想知道是否有人可以告诉msvc 2008/2010是否对此错误给出了更好的诊断? Someone also mentioned GCC should do, can anyone confirm this? 有人还提到海湾合作委员会应该这样做,有人可以确认吗? What about other compilers (Intel?, Comeau?) 那么其他编译器(Intel?,Comeau?)呢?

Thanks 谢谢

I can confirm with Code::Blocks and VC++ 2005, that it gives no hint where the error occurs. 我可以使用Code :: Blocks和VC ++ 2005进行确认,它没有提示发生错误的位置。 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. 除非使用编译器开关来启用更全面的错误诊断,否则这不是我第一次使用GCC(MinGW)编译文件以获得更有用的错误诊断。 (Alas, your code should be free of VC++ extensions.) (A,您的代码应该没有VC ++扩展。)

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. 不确定是否会更容易找到它。

Actually, the best way to workaround this (VS2013 here) seems to crawl over the output window iteratively: 实际上,解决此问题的最佳方法(此处为VS2013)似乎是在输出窗口上反复爬网:

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;" 1 /在输出中收到消息“此诊断发生在编译器生成的函数'X :: X(const X&)'中”时,转到“ X”类,并使用C ++明确删除复制构造函数11表示法:“ 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... 2 /重新编译,现在输出必须显示相同的错误,但子类上会发生诊断,然后再次循环到步骤1以明确删除子类上的复制构造函数,直到达到真正的错误类为止。

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: 如果构建日志中没有足够的信息,则还有一个选项可控制msbuild的详细程度:
Tools->Options->Projects and Solutions->Build and Run->MSBuild project output verbosity 工具->选项->项目和解决方案->构建并运行-> MSBuild项目输出详细信息

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. 如果双击错误列表中的问题并转到输出窗口,则光标将定位到该错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM