From 2b712a66ef69028751b7efc91231ee9c62f27eda Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 18 Apr 2024 09:49:53 +1000 Subject: [PATCH] regcomp_trie: prevent wordlen value not used warning 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. --- regcomp_trie.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/regcomp_trie.c b/regcomp_trie.c index 44490ce80aee..0512fcda24c8 100644 --- a/regcomp_trie.c +++ b/regcomp_trie.c @@ -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) {