@@ -206,7 +206,7 @@ def _compilePattern(self, pattern, nr, varid,
206
206
arg2 = ', const int varid'
207
207
208
208
ret = '// pattern: ' + pattern + '\n '
209
- ret += 'static inline bool match' + \
209
+ ret += 'MAYBE_UNUSED static inline bool match' + \
210
210
str (nr ) + '(' + tokenType + '* tok' + arg2 + ') {\n '
211
211
returnStatement = 'return false;\n '
212
212
@@ -290,7 +290,7 @@ def _compileFindPattern(self, pattern, findmatchnr, endToken, varId):
290
290
more_args += ', int varid'
291
291
292
292
ret = '// pattern: ' + pattern + '\n '
293
- ret += 'template<class T> static inline T * findmatch' + \
293
+ ret += 'template<class T> MAYBE_UNUSED static inline T * findmatch' + \
294
294
str (findmatchnr ) + '(T * start_tok' + more_args + ') {\n '
295
295
ret += ' for (; start_tok' + endCondition + \
296
296
'; start_tok = start_tok->next()) {\n '
@@ -373,7 +373,7 @@ def _compileVerifyTokenMatch(
373
373
if varId :
374
374
more_args = ', const int varid'
375
375
376
- ret = 'static inline bool match_verify' + \
376
+ ret = 'MAYBE_UNUSED static inline bool match_verify' + \
377
377
str (verifyNumber ) + '(const Token *tok' + more_args + ') {\n '
378
378
379
379
origMatchName = 'Match'
@@ -509,7 +509,7 @@ def _compileVerifyTokenFindMatch(
509
509
if varId :
510
510
more_args += ', const int varid'
511
511
512
- ret = 'template < class T > static inline T * findmatch_verify' + \
512
+ ret = 'template < class T > MAYBE_UNUSED static inline T * findmatch_verify' + \
513
513
str (verifyNumber ) + '(T * tok' + more_args + ') {\n '
514
514
515
515
origFindMatchName = 'findmatch'
@@ -721,13 +721,29 @@ def convertFile(self, srcname, destname, line_directive):
721
721
if len (self ._rawMatchFunctions ):
722
722
header += '#include "errorlogger.h"\n '
723
723
header += '#include "token.h"\n '
724
+ header += '#if defined(__clang__)\n '
725
+ header += '#include "config.h"\n '
726
+ header += '#define MAYBE_UNUSED [[maybe_unused]]\n ' # this attribute is also available in earlier standards
727
+ header += 'SUPPRESS_WARNING_CLANG_PUSH("-Wc++17-attribute-extensions")\n ' # suppress waning about using above attribute in earlier standard
728
+ header += '#else\n '
729
+ header += '#define MAYBE_UNUSED\n '
730
+ header += '#endif\n '
731
+
732
+ footer = ''
733
+ if len (self ._rawMatchFunctions ):
734
+ footer += '#if defined(__clang__)\n '
735
+ footer += 'SUPPRESS_WARNING_CLANG_POP\n '
736
+ footer += '#endif\n '
737
+ footer += '#undef MAYBE_UNUSED\n '
724
738
725
739
with io .open (destname , 'wt' , encoding = "utf-8" ) as fout :
726
740
if modified or len (self ._rawMatchFunctions ):
727
741
fout .write (header )
728
742
fout .write (strFunctions )
729
743
fout .write (lineno )
730
744
fout .write (code )
745
+ if modified or len (self ._rawMatchFunctions ):
746
+ fout .write (footer )
731
747
732
748
733
749
def main ():
0 commit comments