diagnostics: %empty enables -Wempty-rule

* src/complain.h, src/complain.c (warning_is_unset): New.
* src/reader.c (grammar_current_rule_empty_set): If enabled -Wempty-rule,
if not disabled.
* tests/actions.at (Implicitly empty rule): Check this feature.
Also check that -Wno-empty-rule does disable this warning.
This commit is contained in:
Akim Demaille
2013-02-16 09:23:48 +01:00
parent f68a49ed49
commit 42d101da8d
4 changed files with 35 additions and 0 deletions

View File

@@ -196,6 +196,15 @@ warning_severity (warnings flags)
}
}
bool
warning_is_unset (warnings flags)
{
size_t b;
for (b = 0; b < warnings_size; ++b)
if (flags & 1 << b && warnings_flag[b] != severity_unset)
return false;
return true;
}
/** Display a "[-Wyacc]" like message on \a f. */

View File

@@ -101,6 +101,9 @@ typedef enum
Wall = ~complaint & ~fatal & ~silent
} warnings;
/** Whether the warnings of \a flags are all unset.
(Never enabled, never disabled). */
bool warning_is_unset (warnings flags);
/** Make a complaint, with maybe a location. */
void complain (location const *loc, warnings flags, char const *message, ...)

View File

@@ -451,6 +451,10 @@ grammar_current_rule_prec_set (symbol *precsym, location loc)
void
grammar_current_rule_empty_set (location loc)
{
/* If %empty is used and -Wno-empty-rule is not, then enable
-Wempty-rule. */
if (warning_is_unset (Wempty_rule))
warning_argmatch ("empty-rule", 0, 0);
if (current_rule->percent_empty_loc.start.file)
complain (&loc, complaint, _("only one %s allowed per rule"), "%empty");
else