Browse Source

add V_FALLTHROUGH for explicit fallthrough

Le Tan 8 years ago
parent
commit
11537972f3
2 changed files with 34 additions and 0 deletions
  1. 26 0
      src/utils/vutils.h
  2. 8 0
      src/utils/vvim.cpp

+ 26 - 0
src/utils/vutils.h

@@ -20,6 +20,32 @@ class VNotebook;
     #define V_ASSERT(cond) ((!(cond)) ? qt_assert(#cond, __FILE__, __LINE__) : qt_noop())
 #endif
 
+// Thanks to CGAL/cgal.
+#ifndef __has_attribute
+    #define __has_attribute(x) 0  // Compatibility with non-clang compilers.
+#endif
+
+#ifndef __has_cpp_attribute
+  #define __has_cpp_attribute(x) 0  // Compatibility with non-supporting compilers.
+#endif
+
+// The fallthrough attribute.
+// See for clang:
+//   http://clang.llvm.org/docs/AttributeReference.html#statement-attributes
+// See for gcc:
+//   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
+#if __has_cpp_attribute(fallthrough)
+#  define V_FALLTHROUGH [[fallthrough]]
+#elif __has_cpp_attribute(gnu::fallthrough)
+#  define V_FALLTHROUGH [[gnu::fallthrough]]
+#elif __has_cpp_attribute(clang::fallthrough)
+#  define V_FALLTHROUGH [[clang::fallthrough]]
+#elif __has_attribute(fallthrough) && ! __clang__
+#  define V_FALLTHROUGH __attribute__ ((fallthrough))
+#else
+#  define V_FALLTHROUGH while(false){}
+#endif
+
 enum class MessageBoxType
 {
     Normal = 0,

+ 8 - 0
src/utils/vvim.cpp

@@ -1115,6 +1115,8 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
         } else {
             break;
         }
+
+        V_FALLTHROUGH;
     }
 
     case Qt::Key_PageUp:
@@ -1381,6 +1383,8 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
         } else {
             break;
         }
+
+        V_FALLTHROUGH;
     }
 
     case Qt::Key_Escape:
@@ -3481,6 +3485,8 @@ void VVim::processDeleteAction(QList<Token> &p_tokens)
                 // Fall through.
                 mayCrossBlock = true;
 
+                V_FALLTHROUGH;
+
             case Range::WordAround:
                 // Fall through.
             case Range::WordInner:
@@ -3712,6 +3718,8 @@ void VVim::processCopyAction(QList<Token> &p_tokens)
                 // Fall through.
                 mayCrossBlock = true;
 
+                V_FALLTHROUGH;
+
             case Range::WordAround:
                 // Fall through.
             case Range::WordInner: