正在提供违反“应"的能力是否需要生成诊断消息,编译器错误/缺陷或功能? [英] Is providing the ability to violate "shall" requirement w/o generation of a diagnostic message a compiler bug / defect or feature?
问题描述
上下文:C标准未将诊断消息归类为警告".或错误".
问题:通过处理某些诊断消息"来解决问题.作为警告"并且通过提供禁用警告生成的能力,某些编译器实施方式允许最终用户违反应"的要求.不生成诊断消息的C标准要求.这是编译器错误/缺陷的津贴吗?如果没有,那么如何正确解释这种情况?作为允许违反应"的编译器"功能,不需要生成诊断消息的要求"?示例:
#pragma警告(禁用:34)typedef int T [];int main(){返回sizeof(T);}
$ cl t28.c/Za<无诊断消息,则应"显示为必须".悄悄地违反了要求[1].
[1] ISO/IEC 9899:1990:
sizeof运算符不得应用于具有函数类型或不完整类型的表达式.
UPD.
- 如果指定了
/Za
(禁用语言扩展),则使用定义1定义了__ STDC __
. - 根据
ANSI一致性
页(但是,- cl
cl
使最终用户能够禁用源于需求的"功能.警告.它是编译器错误/缺陷还是功能?需要正确解释这种情况. - cl
C 2018 6.10.6讨论了 #pragma
指令.第1段说:
…使实现以实现定义的方式运行.该行为可能导致翻译失败或导致翻译器或生成的程序以不符合标准的方式运行.
这很大程度上许可了实现可以执行它想要的任何事情,只要它记录了它即可.如果记录了 #pragma warning(disable:34)
来禁用该警告,那么它就符合要求.
请特别注意 #pragma
可能……导致翻译者……以不符合规定的方式行事."因此,做一些本来就不合规的事情,因为杂用语告诉您要合规.
(我认为原文应该说 #pragma
可能导致翻译器或程序以否则不一致的方式运行.因为,如当前所写,以这种记录的不合格方式表示合格,而不是不合格.)
Context: The C standard does not classify diagnostic messages as "warnings" or "errors".
Question: By treating certain "diagnostic messages" as "warnings" and by giving the ability to disable generation of warnings, certain compiler implementations allow to the end user to violate "shall" requirements of the C standard w/o generation of a diagnostic messages. Is this allowance a compiler bug / defect? If not, then how to correctly interpret this case? As a "compiler feature that allows to violate "shall" requirement w/o generation of a diagnostic message"?
Example:
#pragma warning( disable : 34 )
typedef int T[];
int main()
{
return sizeof(T);
}
$ cl t28.c /Za
<no diagnostic messages, the "shall" requirement [1] is silently violated>
[1] ISO/IEC 9899:1990:
The sizeof operator shall not be applied to an expression that has function type or an incomplete type.
UPD.
- If
/Za
(Disable Language Extensions) is specified, then__STDC__
is defined with definition 1. - According to
ANSI Conformance
page (https://docs.microsoft.com/en-us/cpp/c-language/ansi-conformance?view=msvc-160):
Microsoft C conforms to the standard for the C language as set forth in the 9899:1990 edition of the ANSI C standard.
- However,
cl
gives to the end user the ability to disable "shall requirement originated" warnings. Is it a compiler bug / defect or feature? Need to to correctly interpret this case.
C 2018 6.10.6 discusses the #pragma
directive. Paragraph 1 says:
… causes the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner…
That largely licenses the implementation to do anything it wants, as long as it documents it. If #pragma warning( disable : 34 )
is documented to disable the warning, and that is what it does, then that is conforming.
Note in particular that the #pragma
"might … cause the translator … to behave in a non-conforming manner." So, doing something that is otherwise non-conforming because a pragma told you to is conforming.
(I think the original text should say that the #pragma
may cause the translator or program to behave in an otherwise non-conforming manner. Because, as currently written, behaving in this documented non-conforming manner is conforming, not non-conforming.)
这篇关于正在提供违反“应"的能力是否需要生成诊断消息,编译器错误/缺陷或功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!