Skip to content

Commit b520c74

Browse files
committed
src: ignore maybe-uninitialized warning string_search
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<const Char>, node::stringsearch::Vector<const Char>, 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<const Char>, node::stringsearch::Vector<const Char>, 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.
1 parent 0214b90 commit b520c74

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/string_search.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ class StringSearch : private StringSearchBase {
110110
}
111111

112112
size_t Search(Vector subject, size_t index) {
113+
#if (__GNUC__ >= 8) && !defined(__clang__)
114+
#pragma GCC diagnostic push
115+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
116+
#endif
113117
return (this->*strategy_)(subject, index);
118+
#if (__GNUC__ >= 8) && !defined(__clang__)
119+
#pragma GCC diagnostic pop
120+
#endif
114121
}
115122

116123
static inline int AlphabetSize() {

0 commit comments

Comments
 (0)