> The generated parser produces a GCC warning with "-Wnull-dereference": > > parse.cpp: error: potential null pointer dereference > [-Werror=null-dereference] > > The reason is: > > char const* yyformat = YY_NULLPTR; > > before it's set in a switch for cases 0 to 5. Now, this seems in fact correct > due to "YYERROR_VERBOSE_ARGS_MAXIMUM = 5" and the way the code finally gets > there. But that's a bit much to expect the compiler to recognize. > > Actually I do find the code rather fragile; the definition of > YYERROR_VERBOSE_ARGS_MAXIMUM does not even have a comment pointing out the > ramifications of changing it.
Agreed. That’s also why actually instead of your approach, I would prefer a `default: abort()`. > I also find the code a bit strange at all; why have a number of format strings > that differ only in the number of "or %s" parts, and which must all be > translated individually? Rather than adding repeated parts in a loop, or using > a more flexible wording such as "expecing one of the following: « ? Because of internationalization: you don’t know how it would be translated, how punctuation would be, etc. > Anyway, this patch does just the minimum necessary to avoid the warning (and > make the code more robust in case someone changes > YYERROR_VERBOSE_ARGS_MAXIMUM), by using "default" instead of "case 0 ». But it would be incorrect anyway. Would `default: abort` suit you?
