分开告诉gcc诊断 [英] Telling gcc diagnostics apart

查看:221
本文介绍了分开告诉gcc诊断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解释gcc(4.8.2)警告&错误。更确切地说,很难说出一个问题的结局和另一个问题的开始。我只能使用控制台访问构建机器,因此不能使用IDE。



我真的需要能够快速分辨各个问题。有没有办法让GCC在不同的诊断信息之间插入一些东西?



以下是我得到的输出示例:

  /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:在成员函数'virtual bool xmodel :: Core :: DataItemCollection :: tryAdditionalItemRegistration(std :: shared_ptr< xmodel :: Core :: IDataItem>)const':
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp: 414:66:错误:没有匹配函数调用'bind(<无法解析的重载函数类型> ;, const std :: _占位符&;,const QUuid&)'
,std :: bind(& ; IDataItemCollectionScope :: findItemById,_1,id)
^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:note:候选人是:
包含在/ gl中的文件-sync / compilers / gcc / 4.8.2 / sle11sp0 / include / c ++ / 4.8.2 / bits / stl_algo.h:66:0,
来自/gl-sync/compilers/gcc/4.8.2/sle11sp0 /include/c++/4.8.2/algorithm:62,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,从/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/包括
/QtCore/qhash.h:45,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
来自/ usr2 / viewstore_some / xy01 /xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / ItemId .h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
来自/ usr2 / viewstore_some / xy01 / xy01_unix 1 / fubar / extensions / xmodel / core / code / include / xmodel / core / DataItemDescriptor.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / IDataItemCollection.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
来自/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / src / DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2 / functional:1655:5:note:template< class _Func,class ... _BoundArgs> typename std :: _ Bind_helper std :: _ or_< std :: is_integral< typename std :: decay< _Tp> :: type>,std :: is_enum< typename std :: decay< _Tp> :: type> > :: value,_Func,_BoundArgs ...> :: type std :: bind(_Func&&; _BoundArgs& amp; amp; amp; amp; ...)
bind(_Func&& __f,_BoundArgs&& amp ; ... __args)
^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5:note:template argument deduction /替换失败:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:注意:无法推断模板参数'_Func'
,std :: bind(& IDataItemCollectionScope :: findItemById,_1,id)
^
从/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/包含的文件4.8.2 / bits / stl_algo.h:66:0,来自/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,

from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/在clude / QtCore / qatomic.h:45,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
来自/ gl- sync / thirdparty / Qt / 4.8.4 / lnx_x23.64 / include / QtCore / QHash:1,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h: 11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
来自/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / IDataItem.h:11,
从/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / DataItemDescriptor.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / src / DataItemCo llection.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/ gl-sync / compilers / gcc /4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5:note:template< class _Result,class _Func,class ... _BoundArgs> typename std :: _ Bindres_helper< _Result,_Func,_BoundArgs> :: type std :: bind(_Func&& ;, _BoundArgs&& amp; amp; amp; ...)
bind(_Func&& __f,_BoundArgs&& ;. .. __args)
^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5:note:template argument deduction / substitution failed :
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:注意:无法推断模板参数'_Result'
, std :: bind(& IDataItemCollectionScope :: findItemById,_1,id)
^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp: 417:1:错误:控制达到非void函数的结束[-Werror =返回类型]
}
^

实际上,这个并没有那么糟糕,因为没有涉及宏扩展(我们使用Boost.Preprocessor作为 好)。尽管如此,很难一眼就知道这个输出是关于两个问题的,第二个是最后三行,第一个是在这之前占据整个文本墙。



有没有办法在它们之间插入一些分隔符?即使是一个空白行会做,你可以搜索或 grep 为。



我读过关于控制诊断选项的GCC文档邮件格式,但我找不到任何东西。 [也不可用作搜索锚点,因为并非所有消息都有一个(上面的第一个没有)。

解决方案

分析



我是使用其他人编写的代码(调试SO上的另一个问题,准确地说),并且我压缩了 -Werror 选项以获取警告:

  $ gcc -O3 -g -std = c11 -Wall -Wextra stl.c -o stl 
stl.c:在函数'printStudent ':
stl.c:84:5:warning:format'%s'需要类型'char *'的参数,但参数2的类型为'List'[-Wformat =]
printf(名称:%s,学生 - >第一个);
^
stl.c:84:5:warning:格式'%s'需要类型'char *'的参数,但参数2的类型为'List'[-Wformat =]
stl.c:85:5:warning:格式'%s'需要类型为'char *'的参数,但参数2的类型为'int'[-Wformat =]
printf(Grade:%s \ n,学生 - >年级);
^
stl.c:85:5:warning:格式'%s'需要类型为'char *'的参数,但参数2的类型为'int'[-Wformat =]

并启用 -Werror 以获取错误消息:

  $ gcc -O3 -g -std = c11 -Wall -Wextra -Werror stl.c -o stl 
stl.c:在函数'printStudent'中:
stl.c:84:5:error:格式'%s'需要类型'char *'的参数,但参数2的类型为'List'[ - Werror = format =]
printf(Name:%s,student-> first);
^
stl.c:84:5:error:format'%s'期望类型为'char *'的参数,但参数2的类型为'List'[-Werror = format =]
stl.c:85:5:error:格式'%s'需要类型为'char *'的参数,但参数2的类型为'int'[-Werror = format =]
printf(Grade: %s \ n,学生 - >年级);
^
stl.c:85:5:error:格式'%s'需要'char *'类型的参数,但参数2的类型为'int'[-Werror = format =]
cc1:将所有警告视为错误
$

您会收到一些上下文消息',就像 In function 消息一样,但是每个单独的警告都以< source file>开始:< line>:< col>:warning :,并且每个错误都以包含错误的行开头,代替警告。它继续到下一个上下文消息,或下一个警告或错误消息,或最后的摘要行('所有警告被视为错误')。如果你有额外的信息产生( -H -v 选项),那么生活会更复杂,但用于例行编译,涵盖它。

在您的更广泛的C ++示例中,您有一个上下文消息和两个错误,并带有多个注释来解释为什么第一个错误是。
$ b

综合



因此,可以用合适的标记分割消息。事实上,它可以通过一个简单的 sed 脚本完成:

 <$ c $在GCC警告和错误消息之前插入标记

sed -e'
/^.*:[1- 9] [0-9] *:[1-9] [0-9] *:警告:/ i \
\
- 警告 - \
\

/^.*:[1-9][0-9]*:[1-9][0-9]*:error:/ i\
\
- 错误 - \
\
'$ @

该脚本发现了诊断输出中的第二个错误,这是我在第一眼看过时错过的。

示例



下面是您的示例和我的一些复合输出(加上未编译的编译命令行,其他):

  /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:在成员函数'virtual bool xmodel :: Core :: DataItemCollection :: tryAdditionalItemRegistration(std :: shared_ptr< xmodel ::核心:: IDataItem >)const':

- 错误 -

/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / src / DataItemCollection。 cpp:414:66:error:没有匹配函数调用'bind(<无法解析的重载函数类型> ;, const std :: _占位符&;,const QUuid&)'
,std :: bind (& IDataItemCollectionScope :: findItemById,_1,id)
^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:注:候选人是:
从/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0包含的文件中,
from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/ include / QtCore / qglobal.h:68,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/从/usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11中包含/ QtCore / QHash:1,
,从/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / ItemId.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / IDataItem.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / src / DataItemCollection.h:11,
from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/ 4.8.2 / functional:1655:5:note:template< class _Func,class ... _BoundArgs> typename std :: _ Bind_helper std :: _ or_< std :: is_integral< typename std :: decay< _Tp> :: type>,std :: is_enum< typename std :: decay< _Tp> :: type> > :: value,_Func,_BoundArgs ...> :: type std :: bind(_Func&&; _BoundArgs& amp; amp; amp; amp; ...)
bind(_Func&& __f,_BoundArgs&& amp ; ... __args)
^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5:note:template argument deduction /替换失败:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:注意:无法推断模板参数'_Func'
,std :: bind(& IDataItemCollectionScope :: findItemById,_1,id)
^
从/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/包含的文件中4.8.2 / bits / stl_algo.h:66:0,来自/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,

from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/在clude / QtCore / qatomic.h:45,
来自/gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
来自/ gl- sync / thirdparty / Qt / 4.8.4 / lnx_x23.64 / include / QtCore / QHash:1,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h: 11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
来自/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / IDataItem.h:11,
从/ usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / include / xmodel / core / DataItemDescriptor.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
from / usr2 / viewstore_some / xy01 / xy01_unix1 / fubar / extensions / xmodel / core / code / src / DataItemCo llection.h:11,
来自/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/ gl-sync / compilers / gcc /4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5:note:template< class _Result,class _Func,class ... _BoundArgs> typename std :: _ Bindres_helper< _Result,_Func,_BoundArgs> :: type std :: bind(_Func&& ;, _BoundArgs&& amp; amp; amp; ...)
bind(_Func&& __f,_BoundArgs&& ;. .. __args)
^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5:note:template argument deduction / substitution failed :
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66:注意:无法推断模板参数'_Result'
, std :: bind(& IDataItemCollectionScope :: findItemById,_1,id)
^

- 错误 -

/ usr2 / viewstore_some / xy01 / xy01_unix1 /fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:417:1:错误:控制达到非void函数的结束[-Werror =返回类型]
}
^
'stl'是最新的。
gcc -O3 -g -I / Users / jleffler / inc -std = c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition stl.c -o stl -L / Users / jleffler / lib / 64 -ljl
gcc -O3 -g -I / Users / jleffler / inc -std = c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition stl.c - o stl -L / Users / jleffler / lib / 64 -ljl
stl.c:在函数'printStudent'中:

- 警告 -

stl .c:84:5:warning:格式'%s'需要类型'char *'的参数,但参数2的类型为'List'[-Wformat =]
printf(Name:%s,student - >首先);


- 警告 -

stl.c:84:5:警告:格式'%s'需要'char *'类型的参数,但参数2的类型为'List'[-Wformat =]

- 警告 -

stl.c:85:5:警告:格式'%s'预计参数类型'char *',但参数2的类型为'int'[-Wformat =]
printf(Grade:%s \ n,student-> grade);
$

- 警告 -

stl.c:85:5:警告:格式'%s'需要'char *'类型的参数,但参数2的类型为'int'[-Wformat =]
gcc -O3 -g -I / Users / jleffler / inc -std = c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style -definition -Werror stl.c -o stl -L / Users / jleffler / lib / 64 -ljl
stl.c:在函数'printStudent'中:

- 错误 -

stl.c:84:5:error:格式'%s'需要类型为'char *'的参数,但参数2的类型为'List'[-Werror = format =]
printf(名称:%s,学生 - >第一);


- 错误 -

stl.c:84:5:错误:格式'%s'需要'char *'类型的参数,但参数2的类型为'List'[-Werror = format =]

- 错误 -

stl.c:85:5:error:format'%s '期望类型'char *'的参数,但参数2的类型为'int'[-Werror = format =]
printf(Grade:%s \ n,student-> grade);


- 错误 -

stl.c:85:5:错误:格式'%s'需要'char *'类型的参数,但参数2的类型为'int'[-Werror = format =]
cc1:将所有警告视为错误


I have a problem interpreting gcc (4.8.2) warnings & errors. More precisely, it's difficult to tell where one problem ends and another one starts. I have console-only access to the build machine, so using an IDE is not an option.

I really need to be able to tell individual issues apart quickly. Is there a way to make GCC insert something between distinct diagnostic messages?

Here is an example output I am getting:

/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp: In member function ‘virtual bool xmodel::Core::DataItemCollection::tryAdditionalItemRegistration(std::shared_ptr<xmodel::Core::IDataItem>) const’:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const std::_Placeholder<1>&, const QUuid&)’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note: candidates are:
In file included from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0,
                 from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5: note: template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__or_<std::is_integral<typename std::decay<_Tp>::type>, std::is_enum<typename std::decay<_Tp>::type> >::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...)
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5: note:   template argument deduction/substitution failed:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note:   couldn't deduce template parameter ‘_Func’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
In file included from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0,
                 from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5: note: template<class _Result, class _Func, class ... _BoundArgs> typename std::_Bindres_helper<_Result, _Func, _BoundArgs>::type std::bind(_Func&&, _BoundArgs&& ...)
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5: note:   template argument deduction/substitution failed:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note:   couldn't deduce template parameter ‘_Result’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:417:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^

This one is not even so bad, actually, as there are no macro expansions involved (we use Boost.Preprocessor as well). Still, it's awfully difficult to tell at a glance that this output is about two problems, the second one on the last 3 lines and the first one taking up the entire wall of text before that.

Is there a way to get some separator inserted between them? Even a blank line would do, something you could Search or grep for.

I've read the GCC docs on Options to Control Diagnostic Messages Formatting, but I couldn't find anything. [ is also not usable as a search anchor, because not all the messages have one (the first one above doesn't). I'm out of ideas.

解决方案

Analysis

I am using some code that someone else wrote (debugging for another question on SO, to be precise), and I suppressed the -Werror option to get warnings:

$ gcc -O3 -g -std=c11 -Wall -Wextra stl.c -o stl
stl.c: In function ‘printStudent’:
stl.c:84:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Wformat=]
     printf("Name: %s ", student->first);
     ^
stl.c:84:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Wformat=]
stl.c:85:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
     printf("Grade: %s\n", student->grade);
     ^
stl.c:85:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
$

and enabled -Werror to get error messages:

$ gcc -O3 -g -std=c11 -Wall -Wextra -Werror stl.c -o stl
stl.c: In function ‘printStudent’:
stl.c:84:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Werror=format=]
     printf("Name: %s ", student->first);
     ^
stl.c:84:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Werror=format=]
stl.c:85:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Werror=format=]
     printf("Grade: %s\n", student->grade);
     ^
stl.c:85:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Werror=format=]
cc1: all warnings being treated as errors
$

You get some 'context messages', like the In function messages, but each individual warning starts with <source file>:<line>:<col>: warning:, and each error starts with a line containing error in place of warning. It continues to the next context message, or the next warning or error message, or the final summary line ('all warnings being treated as errors'). If you have extra information being produced (-H, or -v options), then life is more complex, but for routine compilations, that covers it.

In your rather more extensive C++ example, you have a context message plus two errors, with multiple notes to explain why the first error was produced.

Synthesis

It would, therefore, be possible to split up the messages with a suitable marker. In fact, it can be done fairly easily with a simple sed script:

#!/bin/sh
#
# Insert markers before GCC warning and error messages

sed -e '
/^.*:[1-9][0-9]*:[1-9][0-9]*: warning: /i\
\
-- WARNING --\
\

/^.*:[1-9][0-9]*:[1-9][0-9]*: error: /i\
\
-- ERROR --\
\
' "$@"

The script spotted the second error in your diagnostic output, which I'd missed on my first glance through.

Example

Here's some composite output from your example and mine (plus unexpurgated compilation command lines, miscellaneous):

/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp: In member function ‘virtual bool xmodel::Core::DataItemCollection::tryAdditionalItemRegistration(std::shared_ptr<xmodel::Core::IDataItem>) const’:

-- ERROR --

/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const std::_Placeholder<1>&, const QUuid&)’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note: candidates are:
In file included from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0,
                 from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5: note: template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__or_<std::is_integral<typename std::decay<_Tp>::type>, std::is_enum<typename std::decay<_Tp>::type> >::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...)
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1655:5: note:   template argument deduction/substitution failed:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note:   couldn't deduce template parameter ‘_Func’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^
In file included from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/bits/stl_algo.h:66:0,
                 from /gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/algorithm:62,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qglobal.h:68,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qatomic.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/qhash.h:45,
                 from /gl-sync/thirdparty/Qt/4.8.4/lnx_x23.64/include/QtCore/QHash:1,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/rappserv/code/include/convenience/stdhash_quuid.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/ItemId.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItem.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/DataItemDescriptor.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/include/xmodel/core/IDataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.h:11,
                 from /usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:9:
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5: note: template<class _Result, class _Func, class ... _BoundArgs> typename std::_Bindres_helper<_Result, _Func, _BoundArgs>::type std::bind(_Func&&, _BoundArgs&& ...)
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/gl-sync/compilers/gcc/4.8.2/sle11sp0/include/c++/4.8.2/functional:1682:5: note:   template argument deduction/substitution failed:
/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:414:66: note:   couldn't deduce template parameter ‘_Result’
       , std::bind(&IDataItemCollectionScope::findItemById, _1, id)
                                                                  ^

-- ERROR --

/usr2/viewstore_some/xy01/xy01_unix1/fubar/extensions/xmodel/core/code/src/DataItemCollection.cpp:417:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
'stl' is up to date.
    gcc -O3   -g   -I/Users/jleffler/inc   -std=c11   -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition     stl.c -o stl -L/Users/jleffler/lib/64 -ljl
    gcc -O3   -g   -I/Users/jleffler/inc   -std=c11   -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition     stl.c -o stl -L/Users/jleffler/lib/64 -ljl
stl.c: In function ‘printStudent’:

-- WARNING --

stl.c:84:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Wformat=]
     printf("Name: %s ", student->first);
     ^

-- WARNING --

stl.c:84:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Wformat=]

-- WARNING --

stl.c:85:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
     printf("Grade: %s\n", student->grade);
     ^

-- WARNING --

stl.c:85:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
    gcc -O3   -g   -I/Users/jleffler/inc   -std=c11   -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Werror    stl.c -o stl -L/Users/jleffler/lib/64 -ljl
stl.c: In function ‘printStudent’:

-- ERROR --

stl.c:84:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Werror=format=]
     printf("Name: %s ", student->first);
     ^

-- ERROR --

stl.c:84:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘List’ [-Werror=format=]

-- ERROR --

stl.c:85:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Werror=format=]
     printf("Grade: %s\n", student->grade);
     ^

-- ERROR --

stl.c:85:5: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Werror=format=]
cc1: all warnings being treated as errors

这篇关于分开告诉gcc诊断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆