Skip to content

Commit

Permalink
regcomp_trie: prevent wordlen value not used warning
Browse files Browse the repository at this point in the history
This occurs with clang-17, and possibly other versions:

regcomp_trie.c:667:13: warning: variable 'wordlen' set but not used [-Wunused-but-set-variable]
  667 |         U32 wordlen      = 0;         /* required init */
      |             ^

This happens because while the first loop in Perl_make_trie calculates
wordlen, mostly via the TRIE_READ_CHAR macro, that calculated value
isn't used.

The later loops do use the value of wordlen via the TRIE_HANDLE_WORD()
macro.

Unfortunately the use in TRIE_READ_CHAR() means we can't remove
this first definition, so suppress the warning.
  • Loading branch information
tonycoz committed Apr 18, 2024
1 parent 7be2e19 commit 2b712a6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions regcomp_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
STRLEN maxchars = 0;
bool set_bit = trie->bitmap ? 1 : 0; /*store the first char in the
bitmap?*/

/* wordlen is needed for the TRIE_READ_CHAR() macro, but we don't use its
value in this scope, we only modify it. clang 17 warns about this.
The later definitions of wordlen in this function do have their values
used.
*/
PERL_UNUSED_VAR(wordlen);

lastbranch = cur;

if (OP(noper) == NOTHING) {
Expand Down

0 comments on commit 2b712a6

Please sign in to comment.