From b520c74dfd3cd164549dd89ec020dbdc662d9589 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 27 Jan 2020 13:50:13 +0100 Subject: [PATCH 1/3] src: ignore maybe-uninitialized warning string_search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the following compilation warning is generated with GCC version 8.2.1: In file included from ../src/node_buffer.cc:29: ../src/string_search.h: In function ‘size_t node::stringsearch::SearchString( node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = short unsigned int]’: ../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] return (this->*strategy_)(subject, index); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ../src/string_search.h: In function ‘size_t node::stringsearch::SearchString( node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = unsigned char]’: ../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] return (this->*strategy_)(subject, index); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ The issue here seems to be with the `strategy_` field which is a pointer to a member function, and it is set in the constructor of StringSearch. It is always set and I've not been able to work around this warning so this commit suggests adding a pragma for GCC to ignore the warning. --- src/string_search.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/string_search.h b/src/string_search.h index b339c355fe168d..d657320263f9ab 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -110,7 +110,14 @@ class StringSearch : private StringSearchBase { } size_t Search(Vector subject, size_t index) { +#if (__GNUC__ >= 8) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif return (this->*strategy_)(subject, index); +#if (__GNUC__ >= 8) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif } static inline int AlphabetSize() { From 1b3454d428c2001d6915fe1a08303dd0ef8c3e30 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 3 Feb 2020 09:33:26 +0100 Subject: [PATCH 2/3] Revert "src: ignore maybe-uninitialized warning string_search" This reverts commit b520c74dfd3cd164549dd89ec020dbdc662d9589. --- src/string_search.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/string_search.h b/src/string_search.h index d657320263f9ab..b339c355fe168d 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -110,14 +110,7 @@ class StringSearch : private StringSearchBase { } size_t Search(Vector subject, size_t index) { -#if (__GNUC__ >= 8) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif return (this->*strategy_)(subject, index); -#if (__GNUC__ >= 8) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif } static inline int AlphabetSize() { From b1269abf1a05287347fe09212edc08ee8a8f6be5 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 27 Jan 2020 13:50:13 +0100 Subject: [PATCH 3/3] src: ignore maybe-uninitialized warning string_search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the following compilation warning is generated with GCC version 8.2.1: In file included from ../src/node_buffer.cc:29: ../src/string_search.h: In function ‘size_t node::stringsearch::SearchString( node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = short unsigned int]’: ../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] return (this->*strategy_)(subject, index); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ../src/string_search.h: In function ‘size_t node::stringsearch::SearchString( node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = unsigned char]’: ../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] return (this->*strategy_)(subject, index); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ I'm not sure why this works but delegating to the default constructor of the base class StringSearchBase makes this warning go away. --- src/string_search.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_search.h b/src/string_search.h index b339c355fe168d..cec7fcd29113b8 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -91,7 +91,7 @@ class StringSearch : private StringSearchBase { typedef stringsearch::Vector Vector; explicit StringSearch(Vector pattern) - : pattern_(pattern), start_(0) { + : StringSearchBase(), pattern_(pattern), start_(0) { if (pattern.length() >= kBMMaxShift) { start_ = pattern.length() - kBMMaxShift; }