Add -Wimplicit-fallthrough warning flag, which warns on fallthrough between
cases in switch statements. Also add a [[clang::fallthrough]] attribute, which
can be used to suppress the warning in the case of intentional fallthrough.

Patch by Alexander Kornienko!

The handling of C++11 attribute namespaces in this patch is temporary, and will
be replaced with a cleaner mechanism in a subsequent patch.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156086 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html
index ca3ca2a..0952fa0 100644
--- a/docs/LanguageExtensions.html
+++ b/docs/LanguageExtensions.html
@@ -103,6 +103,11 @@
   <li><a href="#__sync_swap">__sync_swap</a></li>
  </ul>
 </li>
+<li><a href="#non-standard-attributes">Non-standard C++11 Attributes</a>
+<ul>
+  <li><a href="#clang__fallthrough">The <tt>clang::fallthrough</tt> attribute</a></li>
+</ul>
+</li>
 <li><a href="#targetspecific">Target-Specific Extensions</a>
   <ul>
   <li><a href="#x86-specific">X86/X86-64 Language Extensions</a></li>
@@ -1497,6 +1502,55 @@
   <li><tt>__c11_atomic_fetch_xor</tt></li>
 </ul>
 
+<!-- ======================================================================= -->
+<h2 id="non-standard-attributes">Non-standard C++11 Attributes</h2>
+<!-- ======================================================================= -->
+
+<p>Clang supports one non-standard C++11 attribute. It resides in <tt>clang</tt>
+namespace.</p>
+
+<!-- ======================================================================= -->
+<h3 id="clang__fallthrough">The <tt>clang::fallthrough</tt> attribute</h3>
+<!-- ======================================================================= -->
+
+<p>The <tt>clang::fallthrough</tt> attribute is used along with
+<tt>-Wimplicit-fallthrough</tt> diagnostic to annotate intentional fall-through
+between switch labels. It can only be applied to a null statement placed in a
+point of execution between any statement and the next switch label. It is common
+to mark these places with a specific comment, but this attribute is meant to
+replace comments with a more strict annotation, which can be checked by the
+compiler. This attribute doesn't change semantics of the code and can be used
+wherever an intended fall-through occurs, but it is designed to mimic
+control-flow statements like <tt>break;</tt> so it can be placed in most places
+where <tt>break;</tt> can, but only if there are no statements on execution path
+between it and the next switch label.</p>
+<p>Here is an example:</p>
+<pre>
+// compile with -Wimplicit-fallthrough
+switch (n) {
+case 33:
+  f();
+case 44:  // warning: unannotated fall-through
+  g();
+  <b>[[clang::fallthrough]];</b>
+case 55:  // no warning
+  if (x) {
+    h();
+    break;
+  }
+  else {
+    i();
+    <b>[[clang::fallthrough]];</b>
+  }
+case 66:  // no warning
+  p();
+  <b>[[clang::fallthrough]];</b>  // warning: fallthrough annotation does not directly
+                           //          preceed case label
+  q();
+case 77:  // warning: unannotated fall-through
+  r();
+}
+</pre>
 
 <!-- ======================================================================= -->
 <h2 id="targetspecific">Target-Specific Extensions</h2>