From 4d1e6e0428c6107853992870d4dfeff376ab3f50 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Sun, 20 Jan 2019 23:12:17 -0500 Subject: [PATCH] a few minor tweaks basked on static analysis suggestions --- CMakeLists.txt | 7 +++++++ Regex/Common.h | 6 +++--- Util/include/Util/utils.h | 4 +++- src/RangesetTable.cpp | 2 +- src/TextArea.cpp | 7 +++++-- src/TextAreaMimeData.h | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e488ad43..6d30e0f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ else() -Wno-unused-macros -Wno-switch-enum -Wno-unknown-pragmas + -Wsuggest-override ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -126,6 +127,12 @@ else() #-Wduplicated-cond #-Wduplicated-branches -Wlogical-op + + #-Wsuggest-attribute=pure + #-Wsuggest-attribute=const + #-Wsuggest-attribute=noreturn + -Wsuggest-final-types + -Wsuggest-final-methods ) endif() endif() diff --git a/Regex/Common.h b/Regex/Common.h index e84b3427..942b4645 100644 --- a/Regex/Common.h +++ b/Regex/Common.h @@ -35,14 +35,14 @@ uint8_t GET_OP_CODE(T *p) noexcept { * escape. *--------------------------------------------------------------------*/ template -R literal_escape(Ch ch) noexcept { +constexpr R literal_escape(Ch ch) noexcept { - static const char valid_escape[] = { + constexpr char valid_escape[] = { 'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '(', ')', '-', '[', ']', '<', '>', '{', '}', '.', '\\', '|', '^', '$', '*', '+', '?', '&', '\0' }; - static const char value[] = { + constexpr char value[] = { '\a', '\b', 0x1B, // Escape character in ASCII character set. '\f', '\n', '\r', '\t', '\v', '(', ')', '-', '[', ']', '<', '>', '{', '}', '.', '\\', '|', '^', '$', '*', '+', '?', '&', '\0' diff --git a/Util/include/Util/utils.h b/Util/include/Util/utils.h index 7f70744d..4438718c 100644 --- a/Util/include/Util/utils.h +++ b/Util/include/Util/utils.h @@ -2,8 +2,10 @@ #ifndef UTILS_H_ #define UTILS_H_ +#include + template -int safe_ctype (Ch c) { +constexpr int safe_ctype (Ch c) { return F(static_cast(c)); } diff --git a/src/RangesetTable.cpp b/src/RangesetTable.cpp index 77f426b7..bbb5c80e 100644 --- a/src/RangesetTable.cpp +++ b/src/RangesetTable.cpp @@ -9,7 +9,7 @@ namespace { // -------------------------------------------------------------------------- -const std::array rangeset_labels = { +constexpr std::array rangeset_labels = { 58, 10, 15, 1, 27, 52, 14, 3, 61, 13, 31, 30, 45, 28, 41, 55, 33, 20, 62, 34, 42, 18, 57, 47, 24, 49, 19, 50, 25, 38, 40, 2, 21, 39, 59, 22, 60, 4, 6, 16, 29, 37, 48, 46, 54, 43, 32, 56, diff --git a/src/TextArea.cpp b/src/TextArea.cpp index 67d3770d..715cb93f 100644 --- a/src/TextArea.cpp +++ b/src/TextArea.cpp @@ -3204,9 +3204,12 @@ void TextArea::TextDResize(bool widthChanged) { the top character no longer pointing at a valid line start */ if (continuousWrap_ && wrapMargin_ == 0 && widthChanged) { const TextCursor oldFirstChar = firstChar_; - nBufferLines_ = TextDCountLines(buffer_->BufStartOfBuffer(), buffer_->BufEndOfBuffer(), /*startPosIsLineStart=*/true); + const TextCursor start = buffer_->BufStartOfBuffer(); + const TextCursor end = buffer_->BufEndOfBuffer(); + + nBufferLines_ = TextDCountLines(start, end, /*startPosIsLineStart=*/true); firstChar_ = TextDStartOfLine(firstChar_); - topLineNum_ = TextDCountLines(buffer_->BufStartOfBuffer(), firstChar_, /*startPosIsLineStart=*/true) + 1; + topLineNum_ = TextDCountLines(start, firstChar_, /*startPosIsLineStart=*/true) + 1; offsetAbsLineNum(oldFirstChar); } diff --git a/src/TextAreaMimeData.h b/src/TextAreaMimeData.h index ed19e288..c9bd9f5c 100644 --- a/src/TextAreaMimeData.h +++ b/src/TextAreaMimeData.h @@ -13,7 +13,7 @@ class TextAreaMimeData : public QMimeData { ~TextAreaMimeData() override = default; public: - QStringList formats() const override; + QStringList formats() const override final; bool hasFormat(const QString &mimeType) const override; protected: