我将Clang错误消息翻译成另一种语言,并且在文件底部附近找到了以下条目:
def warn_unannotated_fallthrough : Warning<
"unannotated fall-through between switch labels">,
InGroup<ImplicitFallthrough>, DefaultIgnore;
和
def warn_unannotated_fallthrough_per_function : Warning<
"unannotated fall-through between switch labels in partly-annotated "
"function">, InGroup<ImplicitFallthroughPerFunction>, DefaultIgnore;
我试图搜索有关这些警告的内容,并找到以下代码片段:
int fallthrough(int n) {
switch (n / 10) {
case 0:
n += 100;
- case 1: // expected-warning{{unannotated fall-through between switch labels in partly annotated method}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+ case 1: // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
switch (n) {
case 111:
n += 111;
[[clang::fallthrough]];
case 112:
n += 112;
- case 113: // expected-warning{{unannotated fall-through between switch labels in partly annotated method}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+ case 113: // expected-warning{{unannotated fall-through}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
n += 113;
break ;
}
Clang的“注释”是什么意思?
最佳答案
在这种情况下,“带注释”可能是指一些特殊的
注释,编译器将识别。为了
例如,“未注释的掉线”(如您的代码中
代码段),这段代码:
case 0:
n += 100;
case 1:
// ...
通常是错误,因为程序员忘记了
break
。因此,编译器将发出警告。在极少数情况下(达夫
例如设备),丢失的中断是有意的;的
“注释”是一种告诉编译器(和其他阅读代码的人)的方法
故意的,并且不发出警告。
从您的示例代码片段中,我收集到clang正在使用新的
C++ 11属性语法,而不是传统的特殊
评论。 (这里的属性是
[[clang::fallthrough]];
声明。)从您的代码段来看,我认为第一个信息是
如果函数不包含任何属性(大多数情况下不会,
因为这是C++ 11的新功能),第二个功能将被使用
如果有的话。 (从用户的 Angular 来看:如果正在
使用,如果缺少的休息是
故意的。如果不是,那么事实并非如此
缺席休息时没有告诉您不是
故意的;您必须仔细看。)
将错误消息翻译成另一种语言
棘手,因为这取决于新C++ 11的公认术语
特征;由于这是一项新功能,因此可能没有
确定的期限。同样有趣的是,clang使用
“带注释”,尽管标准从不使用该术语
“注释”或“注释”。从上下文和您的示例
片段,很明显,“带注释”的意思是“具有C++ 11属性
的形式”,但除此之外,您可能会
必须猜测一下(或以目标语言在论坛中提问:
过去,fr.comp.lang.c++对于法语非常有用,因为
例)。