yohhoyの日記

技術的メモをしていきたい日記

C++11属性と空文

C++11の属性(attribute)は空文に対しても指定可能。

Clangではswitch構文caseラベルにてfall-through動作を明示できる。このとき空文(;のみ)に独自拡張のclang::fallthrough属性を指定する。

The clang::fallthrough attribute

// compile with -Wimplicit-fallthrough
switch (n) {
case 22:
case 33:  // no warning: no statements between case labels
  f();
case 44:  // warning: unannotated fall-through
  g();
  [[clang::fallthrough]];
case 55:  // no warning
  // (snip)
}
Clang Language Extensions - Non-standard C++11 Attributes

C++11(N3337) A.5 Statementsより構文定義を一部引用。

statement:
 attribute-specifier-seqopt expression-statement
 (snip)

expression-statement:
 expressionopt ;
 (snip)

関連URL