westes / flex

The Fast Lexical Analyzer - scanner generator for lexing in C and C++
Other
3.62k stars 536 forks source link

[2.6.4] Clang warns of unreachable code for `%option noyywrap` but not for an actual wrap function. #406

Open uprego opened 5 years ago

uprego commented 5 years ago

There is for flex 2.6.4 (but not for e.g. flex 2.5.35 Apple(flex-31)) a warning (if Clang is used with -Wunreachable-code) at this line, in the generated scanner:

https://github.com/westes/flex/blob/98018e3f58d79e082216d406866942841d4bdf8a/src/flex.skl#L1394

This doesn't happen when using an actual yywrap function, but is happening to me when using %option noyywrap.

I don't remember setting that compiler flag on, but I rather think it was Xcode that switched it on using some default configuration. This is the main reason why I think it is worth mentioning. And %option noyywrap apparently not having the same consequence as an empty wrap function.

See also https://lists.gnu.org/archive/html/help-bison/2018-11/msg00046.html up the thread for a similar issue at Bison.

Of course if you need some code example, I would give you one.

uprego commented 5 years ago

The similar issue I reported to the Bison maintainer was considered and a patch was added, included in versions later than 3.2.1:

http://git.savannah.gnu.org/cgit/bison.git/commit/?id=cc050fd3

https://github.com/akimd/bison/commit/cc050fd3

Makes me wonder, is there anything I can do for this? Or, if anyone knowing that I was doing anything wrong, can point me to it?

I can fix my warning for 2.6.4 just by adding the empty actual yywrap, I reported this for the software, not for me.

flex 2.5.35 Apple(flex-31) will be alright with %option noyywrap, apart from some offending docstrings, unrelated to this issue, I would at this point simply fix or wipe out using an ad hoc sed thing.