From 11537972f30eac3eb578577bcc8a2596915ec7ff Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sun, 8 Oct 2017 21:16:08 +0800 Subject: [PATCH] add V_FALLTHROUGH for explicit fallthrough --- src/utils/vutils.h | 26 ++++++++++++++++++++++++++ src/utils/vvim.cpp | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/src/utils/vutils.h b/src/utils/vutils.h index d0886dde..f3e75bb9 100644 --- a/src/utils/vutils.h +++ b/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, diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp index 74bb2c1c..940b08a8 100644 --- a/src/utils/vvim.cpp +++ b/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 &p_tokens) // Fall through. mayCrossBlock = true; + V_FALLTHROUGH; + case Range::WordAround: // Fall through. case Range::WordInner: @@ -3712,6 +3718,8 @@ void VVim::processCopyAction(QList &p_tokens) // Fall through. mayCrossBlock = true; + V_FALLTHROUGH; + case Range::WordAround: // Fall through. case Range::WordInner: