From be2b3c91ae4ddb97c35237da11b350c99cc6fd3b Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 14 Jul 2017 13:44:33 +0200 Subject: Add Q_FALLTHROUGH for Qt < 5.8 ... and make use of it. With gcc 7, the new option -Wimplicit-fallthrough is introduced and added to the -Wextra set, triggering dozens of warnings in our sources. Therefore, we annotate all obviously intended fall-throughs. The ones that are still left are unclear and need to be checked by the respective maintainer. Change-Id: I44ead33cd42a4b41c28ee5fcb5a31db272710bbc Reviewed-by: Nikita Baryshnikov Reviewed-by: hjk Reviewed-by: Eike Ziller --- src/libs/3rdparty/cplusplus/Parser.cpp | 4 ++- src/libs/utils/qtcfallthrough.h | 54 ++++++++++++++++++++++++++++++++++ src/libs/utils/utils-lib.pri | 1 + src/libs/utils/utils.qbs | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/libs/utils/qtcfallthrough.h (limited to 'src/libs') diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 8754206a0b..16f351077a 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -27,6 +27,8 @@ #include "ObjectiveCTypeQualifiers.h" #include "QtContextKeywords.h" +#include + #include #include @@ -442,7 +444,7 @@ bool Parser::skipUntilStatement() case T_AT_THROW: if (_languageFeatures.objCEnabled) return true; - + Q_FALLTHROUGH(); default: consumeToken(); } diff --git a/src/libs/utils/qtcfallthrough.h b/src/libs/utils/qtcfallthrough.h new file mode 100644 index 0000000000..6eba622837 --- /dev/null +++ b/src/libs/utils/qtcfallthrough.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +#ifndef Q_FALLTHROUGH +#ifndef QT_HAS_CPP_ATTRIBUTE +#ifdef __has_cpp_attribute +# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +# define QT_HAS_CPP_ATTRIBUTE(x) 0 +#endif +#endif +#if defined(__cplusplus) +#if QT_HAS_CPP_ATTRIBUTE(fallthrough) +# define Q_FALLTHROUGH() [[fallthrough]] +#elif QT_HAS_CPP_ATTRIBUTE(clang::fallthrough) +# define Q_FALLTHROUGH() [[clang::fallthrough]] +#elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough) +# define Q_FALLTHROUGH() [[gnu::fallthrough]] +#endif +#endif +#ifndef Q_FALLTHROUGH +# if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL) +# define Q_FALLTHROUGH() __attribute__((fallthrough)) +# else +# define Q_FALLTHROUGH() (void)0 +#endif +#endif +#endif diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index bfc9d6084e..3a6aa0a09a 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -239,6 +239,7 @@ HEADERS += \ $$PWD/asconst.h \ $$PWD/smallstringfwd.h \ $$PWD/optional.h \ + $$PWD/qtcfallthrough.h \ $$PWD/../3rdparty/optional/optional.hpp FORMS += $$PWD/filewizardpage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 559129df16..6d68683fdd 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -175,6 +175,7 @@ Project { "proxycredentialsdialog.cpp", "proxycredentialsdialog.h", "proxycredentialsdialog.ui", + "qtcfallthrough.h", "qtcassert.cpp", "qtcassert.h", "qtcolorbutton.cpp", -- cgit v1.2.3 From be3e12c8aff85e133f7a3cddb1c0a9ecf8607467 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 14 Jul 2017 12:38:06 +0200 Subject: CppEditor: Avoid auto insertion of '}' in empty line ...when typing '{'. Change-Id: Ia1d3bcd7440c96ed3c8c1479148dd74d3d291689 Reviewed-by: David Schulz --- src/libs/cplusplus/MatchingText.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp index f783d4c508..3fdb573b91 100644 --- a/src/libs/cplusplus/MatchingText.cpp +++ b/src/libs/cplusplus/MatchingText.cpp @@ -143,9 +143,13 @@ bool MatchingText::contextAllowsAutoParentheses(const QTextCursor &cursor, if (!textToInsert.isEmpty()) ch = textToInsert.at(0); + if (ch == QLatin1Char('{') && cursor.block().text().trimmed().isEmpty()) + return false; // User just might want to wrap up some lines. + if (!shouldInsertMatchingText(cursor) && ch != QLatin1Char('\'') && ch != QLatin1Char('"')) return false; - else if (isInCommentHelper(cursor)) + + if (isInCommentHelper(cursor)) return false; return true; -- cgit v1.2.3