From 2983e63983cd3d65a9b56a642a000a088897e7c6 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Sun, 1 Apr 2018 11:45:42 +0300 Subject: [PATCH] [kstyle] use Q_FALLTHROUGH in breezesplitterproxy Summary: Qt has its own macro to tell the compiler that the lack of the break statement is intentional. One of the advantages of using Q_FALLTHROUGH is that it explicitly says other developers that the break statement is missing on purpose. Another advantage is that we can use directives, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817 Test Plan: Compiled Breeze with GCC 7 and Clang, no "this statement may fall through" warnings whatsoever. Reviewers: #breeze, davidedmundson Reviewed By: davidedmundson Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D11860 --- kstyle/breezesplitterproxy.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/kstyle/breezesplitterproxy.cpp b/kstyle/breezesplitterproxy.cpp index 17a15880..3079c7fc 100644 --- a/kstyle/breezesplitterproxy.cpp +++ b/kstyle/breezesplitterproxy.cpp @@ -26,6 +26,28 @@ #include #include +// Q_FALLTHROUGH() for Qt < 5.8 +#ifndef Q_FALLTHROUGH +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(fallthrough) +#define Q_FALLTHROUGH() [[fallthrough]] +#elif __has_cpp_attribute(clang::fallthrough) +#define Q_FALLTHROUGH() [[clang::fallthrough]] +#elif __has_cpp_attribute(gnu::fallthrough) +#define Q_FALLTHROUGH() [[gnu::fallthrough]] +#endif +#endif +#ifndef Q_FALLTHROUGH +#if defined(Q_CC_GNU) && Q_CC_GNU >= 700 +#define Q_FALLTHROUGH() __attribute__((fallthrough)) +#elif defined(Q_CC_CLANG) && Q_CC_CLANG >= 305 +#define Q_FALLTHROUGH() [[clang::fallthrough]] +#else +#define Q_FALLTHROUGH() +#endif +#endif +#endif + namespace Breeze { @@ -269,12 +291,13 @@ namespace Breeze if( static_cast( event )->timerId() != _timerId ) { return QWidget::event( event ); } - // fall-through /* Fall through is intended. We somehow lost a QEvent::Leave before timeout. We fix it from here */ + Q_FALLTHROUGH(); + case QEvent::HoverLeave: case QEvent::Leave: {