I'm translating Clang error messages into another language, and near the bottom of the file I found the following entries:
def warn_unannotated_fallthrough : Warning<
"unannotated fall-through between switch labels">,
InGroup<ImplicitFallthrough>, DefaultIgnore;
and
def warn_unannotated_fallthrough_per_function : Warning<
"unannotated fall-through between switch labels in partly-annotated "
"function">, InGroup<ImplicitFallthroughPerFunction>, DefaultIgnore;
I attempted to search for mentions of these warnings, and found this code snipplet:
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 ;
}
What does Clang mean by "annotated"?
By the way, from C++17 standard attribute [[fallthrough]]
is available to indicate that isn't a warning when the code is meant to fall through.
After checking your switch-case on logical mistakes in place where a case ended without break
just use new attribute:
#include <iostream>
enum class Layers {
Undefined, Back, Middle, Front
};
int main() {
Layers layer{ Layers::Undefined };
// ...
switch (layer)
{
case Layers::Back:
std::cout << "Back layer processed" << std::endl;
break;
case Layers::Middle:
std::cout << "Middle layer partially processed" << std::endl;
[[fallthrough]]; //(dont forget the semicolon) Suppressed warning
case Layers::Front:
std::cout << "And some code for middle and front layers" << std::endl;
break;
case Layers::Undefined:
std::cout << "Undefined layer" << std::endl;
}
}
In this case, "annotated" probably refers to some special comments, that the compiler will recognize. For the "unannotated fall-through", for example (as in your code snippet), the bit of code:
case 0:
n += 100;
case 1:
// ...
is usually an error, due to the programmer forgetting a break
.
So the compiler will emit a warning. In some rare cases (Duff's
device, for example), the missing break is intentional; the
"annotation" is a way of telling the compiler (and other people reading the code) that it is
intentional, and to not emit the warning.
From your example snippet, I gather that clang is using the new
C++11 attribute syntax, rather than the traditional special
comments. (The attribute here is the [[clang::fallthrough]];
statement.)
Judging from your snippet, I gather that the first message is used if the function contains no attributes (and most won't, since this is a new C++11 feature), and the second will be used if it does. (From a user point of view: if attributes are being used, one would expect them if the missing break was intentional. If they're not, then the fact that they aren't present on a missing break doesn't tell you that it wasn't intentional; you have to look closer.)
Translating the error messages into another language is probably tricky, since it depends on the accepted term for the new C++11 feature; since it's a new feature, there may not be an established term. Also it's interesting to note that clang uses "annotated", although the standard never uses the term "annotate" or "annotation". From context, and your example snippet, it's clear that "annotated" means "has C++11 attributes of a particular form", but beyond that, you're probably going to have to guess a bit (or ask in a forum in the target language: in the past, fr.comp.lang.c++ was very good for French, for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With