diff --git a/configure b/configure index c9341ebe..1d31fbd2 100755 --- a/configure +++ b/configure @@ -4853,7 +4853,7 @@ printf "%s\n" "#define uint64_t $ac_cv_c_uint64_t" >>confdefs.h # if CXXFLAGS is undefined, set it to our preferred default flags -: ${CXXFLAGS="-Wall -Wextra -Wunused -O2"} +: ${CXXFLAGS="-Wall -Wextra -Wunused -Wshadow -O2"} ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' diff --git a/configure.ac b/configure.ac index 4ae5eda1..34646585 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ AC_TYPE_UINT32_T AC_TYPE_UINT64_T # if CXXFLAGS is undefined, set it to our preferred default flags -: ${CXXFLAGS="-Wall -Wextra -Wunused -O2"} +: ${CXXFLAGS="-Wall -Wextra -Wunused -Wshadow -O2"} AC_LANG([C++]) AC_PROG_CXX diff --git a/lib/Make b/lib/Make index ff43bad7..a1ca475d 100644 --- a/lib/Make +++ b/lib/Make @@ -10,7 +10,7 @@ CPP=c++ AR=ar RANLIB=ranlib COFLAGS=-O2 -CWFLAGS=-Wall -Wunused -Wextra +CWFLAGS=-Wall -Wunused -Wextra -Wshadow CIFLAGS=-I. -I../include CMFLAGS= # CMFLAGS=-DDEBUG diff --git a/lib/convert.cpp b/lib/convert.cpp index 37f2988b..bab61683 100644 --- a/lib/convert.cpp +++ b/lib/convert.cpp @@ -2017,7 +2017,6 @@ std::string convert(const char *pattern, const char *signature, convert_flag_typ ++pos; loc = pos; const std::string& subregex = expand(macros, pattern, len, pos); - int c; if ((flags & convert_flag::lex) && pos + 5 < len && pattern[pos + 1] == '{' && ((c = pattern[pos + 2]) == '+' || c == '|' || c == '&' || c == '-') && pattern[pos + 3] == '}') { size_t subpos = 0; diff --git a/lib/matcher.cpp b/lib/matcher.cpp index efccefc8..fe544bab 100644 --- a/lib/matcher.cpp +++ b/lib/matcher.cpp @@ -3451,7 +3451,7 @@ bool Matcher::advance_string_bm(size_t loc) } else { - size_t k = bms[static_cast(*q)]; + k = bms[static_cast(*q)]; if (p + k > t + bmd) s += k - (t - p); else @@ -3510,7 +3510,7 @@ bool Matcher::advance_string_bm_pma(size_t loc) } else { - size_t k = bms[static_cast(*q)]; + k = bms[static_cast(*q)]; if (p + k > t + bmd) s += k - (t - p); else @@ -3570,7 +3570,7 @@ bool Matcher::advance_string_bm_pmh(size_t loc) } else { - size_t k = bms[static_cast(*q)]; + k = bms[static_cast(*q)]; if (p + k > t + bmd) s += k - (t - p); else diff --git a/lib/pattern.cpp b/lib/pattern.cpp index 4f5ae3d8..1c434756 100644 --- a/lib/pattern.cpp +++ b/lib/pattern.cpp @@ -795,9 +795,9 @@ void Pattern::parse( bol_ = false; bool quote = false; #ifdef WITH_TREE_DFA - DFA::State *t = tfa_.start(); + DFA::State *r = tfa_.start(); #else - Tree::Node *t = tfa_.root(); + Tree::Node *r = tfa_.root(); #endif while (loc < end) { @@ -830,14 +830,14 @@ void Pattern::parse( c = lowercase(c); } #ifdef WITH_TREE_DFA - DFA::State::Edges::iterator i = t->edges.find(c); - if (i == t->edges.end()) + DFA::State::Edges::iterator i = r->edges.find(c); + if (i == r->edges.end()) { if (last_state == NULL) - last_state = t; // t points to the tree DFA start state + last_state = r; // r points to the tree DFA root (start state) DFA::State *target_state = last_state = last_state->next = tfa_.state(); - t->edges[c] = DFA::State::Edge(c, target_state); - t = target_state; + r->edges[c] = DFA::State::Edge(c, target_state); + r = target_state; ++eno_; ++vno_; if (vno_ > DFA::MAX_STATES) @@ -845,14 +845,14 @@ void Pattern::parse( } else { - t = i->second.second; + r = i->second.second; } #else - t = tfa_.edge(t, c); + r = tfa_.edge(r, c); #endif } - if (t->accept == 0) - t->accept = choice; + if (r->accept == 0) + r->accept = choice; #ifdef WITH_TREE_DFA acc_.resize(choice, false); acc_[choice - 1] = true; @@ -1165,12 +1165,12 @@ void Pattern::parse3( } else if (c == '{') // {n,m} repeat min n times to max m { - size_t k = 0; + size_t d = 0; for (Location i = 0; i < 7 && std::isdigit(c = at(++loc)); ++i) - k = 10 * k + (c - '0'); - if (k > Position::MAXITER) + d = 10 * d + (c - '0'); + if (d > Position::MAXITER) error(regex_error::exceeds_limits, loc); - Iter n = static_cast(k); + Iter n = static_cast(d); Iter m = n; bool unlimited = false; if (at(loc) == ',') @@ -2378,9 +2378,9 @@ void Pattern::compile_transition( error(regex_error::exceeds_limits, loc); state->heads.insert(l); } - Lookahead k = n; + Lookahead l = n; n += static_cast(i->second.size()); - if (n < k) + if (n < l) error(regex_error::exceeds_limits, loc); } } @@ -2402,9 +2402,9 @@ void Pattern::compile_transition( error(regex_error::exceeds_limits, loc); state->tails.insert(l); } - Lookahead k = n; + Lookahead l = n; n += static_cast(i->second.size()); - if (n < k) + if (n < l) error(regex_error::exceeds_limits, loc); } } @@ -3049,9 +3049,9 @@ void Pattern::encode_dfa(DFA::State *start) void Pattern::gencode_dfa(const DFA::State *start) const { #ifndef WITH_NO_CODEGEN - for (std::vector::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i) + for (std::vector::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it) { - const std::string& filename = *i; + const std::string& filename = *it; size_t len = filename.length(); if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0) || (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0) @@ -3521,9 +3521,9 @@ void Pattern::gencode_dfa_closure(FILE *file, const DFA::State *state, int nest, void Pattern::graph_dfa(const DFA::State *start) const { #ifndef WITH_NO_CODEGEN - for (std::vector::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i) + for (std::vector::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it) { - const std::string& filename = *i; + const std::string& filename = *it; size_t len = filename.length(); if ((len > 3 && filename.compare(len - 3, 3, ".gv") == 0) || (len > 4 && filename.compare(len - 4, 4, ".dot") == 0)) @@ -3694,9 +3694,9 @@ void Pattern::export_code() const #ifndef WITH_NO_CODEGEN if (nop_ == 0) return; - for (std::vector::const_iterator i = opt_.f.begin(); i != opt_.f.end(); ++i) + for (std::vector::const_iterator it = opt_.f.begin(); it != opt_.f.end(); ++it) { - const std::string& filename = *i; + const std::string& filename = *it; size_t len = filename.length(); if ((len > 2 && filename.compare(len - 2, 2, ".h" ) == 0) || (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0) @@ -4586,7 +4586,7 @@ void Pattern::gen_match_hfa(DFA::State *start) { HFA::HashRanges& set_ranges = hfa_.hashes[level][next->first->index]; HFA::HashRanges& get_ranges = next->second; - for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset) + for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset <= level; ++offset) set_ranges[offset].swap(get_ranges[offset]); } } @@ -4635,7 +4635,7 @@ bool Pattern::gen_match_hfa_transitions(size_t level, size_t& max_level, DFA::St Char lo = edge.lo(); Char hi = edge.hi(); DBGLOG("%zu HFA %p: %u..%u -> %p", level, state, lo, hi, next_state); - for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset) + for (size_t offset = std::max(HFA::MAX_CHAIN - 1, level) + 1 - HFA::MAX_CHAIN; offset < level; ++offset) { DBGLOGN(" offset%3zu", offset); HFA::HashRange& next_hashes = hashes[next_state][offset]; diff --git a/src/Make b/src/Make index ebe8e0af..4b7dcf52 100644 --- a/src/Make +++ b/src/Make @@ -9,7 +9,7 @@ CPP=c++ INCS=../include/reflex/convert.h ../include/reflex/debug.h ../include/reflex/error.h ../include/reflex/input.h ../include/reflex/pattern.h ../include/reflex/utf8.h LIBS=../lib/libreflex.a COFLAGS=-O2 -CWFLAGS=-Wall -Wunused -Wextra +CWFLAGS=-Wall -Wunused -Wextra -Wshadow CIFLAGS=-I. -I../include CMFLAGS= # CMFLAGS=-DDEBUG diff --git a/src/reflex.cpp b/src/reflex.cpp index 537c2a9e..fea32f3e 100644 --- a/src/reflex.cpp +++ b/src/reflex.cpp @@ -381,13 +381,13 @@ void Reflex::init(int argc, char **argv) size_t pos; while ((pos = name.find('-')) != std::string::npos) name[pos] = '_'; - StringMap::iterator i = options.find(name); - if (i == options.end()) + StringMap::iterator it = options.find(name); + if (it == options.end()) help("unknown option --", arg); if (val != NULL) - i->second = val + 1; + it->second = val + 1; else - i->second = "true"; + it->second = "true"; } is_grouped = false; break;