What are "annotated fallthrough" and "partly annotated method" in Clang's wording?

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).


"Annotating" in this case is telling compiler that you intented to skip break in switch case. This way compiler is showing you places that you maybe forgot about break. You can then check it out again and confirm if that was intented.

Tags:

C++

C

Clang