为什么GCC的诊断实用程序在某些警告类型中失败?

时间:2022-06-27 16:05:09

I've noticed only some warnings are supported by GCC's diagnostic pragma.

我注意到GCC的诊断实用程序只支持一些警告。

this works:

如此:

#pragma GCC diagnostic error "-Wconversion"

this fails:

这个操作失败:

#pragma GCC diagnostic error "-Wframe-larger-than=32"

... with the error:

…错误:

error: unknown option after '#pragma GCC diagnostic' kind [-Werror=pragmas]
#pragma GCC diagnostic error "-Wframe-larger-than"

..both of these arguments work with GCC when passed as command line arguments.

. .当作为命令行参数传递时,这两个参数都可以使用GCC。


Is there any documentation for which warnings are supported by the GCC diagnostic pragma?

GCC诊断实用程序支持哪些警告的文档?

2 个解决方案

#1


3  

This is best thing that I've found:
GCC manual at this:

这是我找到的最好的东西:GCC手册:

pragma GCC diagnostic kind option:
Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.

实用GCC诊断类选项:修改诊断的配置。注意,并非所有诊断都是可修改的;目前只有警告(通常由“-W…”控制)可以被控制,而不是全部。使用-fdiagnostics-show-option来确定哪些诊断是可控的,哪些选项控制它们。

and GCC manual at this:

以及GCC手册:

Right now, only the C++ front end can honor these options.
....
-fdiagnostics-show-option:
This option instructs the diagnostic machinery to add text to each diagnostic emitted, which indicates which command line option directly controls that diagnostic, when such an option is known to the diagnostic machinery.

现在,只有c++前端可以纪念这些选项。....-fdiagnostics-show-option:该选项指示诊断机器向发出的每个诊断添加文本,该文本指示当诊断机器知道该选项时,哪个命令行选项直接控制该诊断。

#2


3  

I suspect that you have find a bug in GCC for this specific option.

我怀疑您在GCC中找到了这个特定选项的bug。

With following basic example (see it live):

以下是一些基本的例子:

#include <stdio.h>

int main(void)
{
    int i = 4;

    printf("%d\n", i);

    return 0;
}

which is compiled with -Wframe-larger-than=2 there is clearly a warning message:

它是用- wframle -than=2编译的,显然有一个警告信息:

warning: the frame size of 16 bytes is larger than 2 bytes [-Wframe-larger-than=]

警告:16字节的帧大小大于2字节[-Wframe-larger-than=]

However with combination of -Werror= (i.e. full flag is -Werror=frame-larger-than=2) it behaves in strange way:

但是结合-Werror=(即full flag is -Werror=frame-larger-than=2),其行为方式比较奇怪:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

错误:16字节的帧大小大于1字节[-Werror=frame-larger-than=]

What is even more strange is that it looks that value is completely ignored, as -Werror=frame-larger-than=64 still produces the same error, despite that treshold value is satisfied (i.e. 16 < 64)

更奇怪的是,这个值看起来完全被忽略了,因为-Werror=frame-larger-than=64仍然产生相同的错误,尽管treshold值得到了满足(即16 < 64)

(side note: GCC version is 4.9.0)

(注:GCC版本为4.9.0)

I believe that -Werror= option handling is somehow connected with #pragma GCC diagnostic error, as following seems to work:

我认为-Werror=选项处理与#pragma GCC诊断错误有关,如下所示:

#include <stdio.h>

#pragma GCC diagnostic error "-Wframe-larger-than="
int main(void)
{
    int i = 4;

    printf("%d\n", i);

    return 0;
}

returning an error as:

返回一个错误:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

错误:16字节的帧大小大于1字节[-Werror=frame-larger-than=]

but it fails to cooperate with any value, like:

但它不能与任何价值合作,比如:

#pragma GCC diagnostic error "-Wframe-larger-than=2"

produces:

生产:

warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

警告:“#pragma GCC diagnostic”类(-Wpragmas)之后的未知选项

#1


3  

This is best thing that I've found:
GCC manual at this:

这是我找到的最好的东西:GCC手册:

pragma GCC diagnostic kind option:
Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.

实用GCC诊断类选项:修改诊断的配置。注意,并非所有诊断都是可修改的;目前只有警告(通常由“-W…”控制)可以被控制,而不是全部。使用-fdiagnostics-show-option来确定哪些诊断是可控的,哪些选项控制它们。

and GCC manual at this:

以及GCC手册:

Right now, only the C++ front end can honor these options.
....
-fdiagnostics-show-option:
This option instructs the diagnostic machinery to add text to each diagnostic emitted, which indicates which command line option directly controls that diagnostic, when such an option is known to the diagnostic machinery.

现在,只有c++前端可以纪念这些选项。....-fdiagnostics-show-option:该选项指示诊断机器向发出的每个诊断添加文本,该文本指示当诊断机器知道该选项时,哪个命令行选项直接控制该诊断。

#2


3  

I suspect that you have find a bug in GCC for this specific option.

我怀疑您在GCC中找到了这个特定选项的bug。

With following basic example (see it live):

以下是一些基本的例子:

#include <stdio.h>

int main(void)
{
    int i = 4;

    printf("%d\n", i);

    return 0;
}

which is compiled with -Wframe-larger-than=2 there is clearly a warning message:

它是用- wframle -than=2编译的,显然有一个警告信息:

warning: the frame size of 16 bytes is larger than 2 bytes [-Wframe-larger-than=]

警告:16字节的帧大小大于2字节[-Wframe-larger-than=]

However with combination of -Werror= (i.e. full flag is -Werror=frame-larger-than=2) it behaves in strange way:

但是结合-Werror=(即full flag is -Werror=frame-larger-than=2),其行为方式比较奇怪:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

错误:16字节的帧大小大于1字节[-Werror=frame-larger-than=]

What is even more strange is that it looks that value is completely ignored, as -Werror=frame-larger-than=64 still produces the same error, despite that treshold value is satisfied (i.e. 16 < 64)

更奇怪的是,这个值看起来完全被忽略了,因为-Werror=frame-larger-than=64仍然产生相同的错误,尽管treshold值得到了满足(即16 < 64)

(side note: GCC version is 4.9.0)

(注:GCC版本为4.9.0)

I believe that -Werror= option handling is somehow connected with #pragma GCC diagnostic error, as following seems to work:

我认为-Werror=选项处理与#pragma GCC诊断错误有关,如下所示:

#include <stdio.h>

#pragma GCC diagnostic error "-Wframe-larger-than="
int main(void)
{
    int i = 4;

    printf("%d\n", i);

    return 0;
}

returning an error as:

返回一个错误:

error: the frame size of 16 bytes is larger than 1 bytes [-Werror=frame-larger-than=]

错误:16字节的帧大小大于1字节[-Werror=frame-larger-than=]

but it fails to cooperate with any value, like:

但它不能与任何价值合作,比如:

#pragma GCC diagnostic error "-Wframe-larger-than=2"

produces:

生产:

warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

警告:“#pragma GCC diagnostic”类(-Wpragmas)之后的未知选项