checkrule::checkrule (std::string const &a_name, action_t an_action)
: _m_name (a_name)
, _m_action (an_action)
+ , _m_used (false)
{
}
+checkrule_internal::checkrule_internal (std::string const &a_name,
+ action_t an_action)
+ : checkrule (a_name, an_action)
+{
+ mark_used ();
+}
+
namespace
{
bool
{
std::string const &rule_name = it->name ();
bool nflag = it->action () == checkrule::request;
- if (nflag == should)
+ if (nflag == should && it->used ())
continue;
for (checkstack::const_iterator jt = stack.begin ();
jt != stack.end (); ++jt)
if (rule_matches (rule_name, **jt))
{
+ it->mark_used ();
//std::cout << " rule: " << rule_name << " " << nflag << std::endl;
should = nflag;
break;
private:
std::string _m_name;
action_t _m_action;
+ mutable bool _m_used;
public:
checkrule (std::string const &name, action_t action);
std::string const &name () const { return _m_name; }
action_t action () const { return _m_action; }
+ bool used () const { return _m_used; }
+ void mark_used () const { _m_used = true; }
+};
+
+// These are like normal rules, but they are initially marked as used
+// so as not to be warned about.
+struct checkrule_internal
+ : public checkrule
+{
+ checkrule_internal (std::string const &name, action_t action);
};
class checkrules
: public checkrules
{
initial_checkrules () {
- push_back (checkrule ("@all", checkrule::request));
- push_back (checkrule ("@nodefault", checkrule::forbid));
+ push_back (checkrule_internal ("@all", checkrule::request));
+ push_back (checkrule_internal ("@nodefault", checkrule::forbid));
}
} rules;
}
while (++remaining < argc);
+ for (checkrules::const_iterator it = check_option.rules.begin ();
+ it != check_option.rules.end (); ++it)
+ if (!it->used ())
+ std::cerr << "warning: the rule `" << it->name ()
+ << "' never matched." << std::endl;
+
return error_count != 0;
}
testrun_compare ./dwarflint -q -i nodebug <<EOF
EOF
+
+# This has nothing to do with the nodebug test, but we can just as
+# well stick it in there.
+testrun_compare ./dwarflint --check=oentuh -q nodebug <<EOF
+warning: the rule \`oentuh' never matched.
+EOF