3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-03 13:56:08 +00:00

Use "override" keyword where needed. (#9892)

This is another PR towards the goal of getting Z3 to compile cleanly
when included via FetchContents into clang-tidy, which uses a pretty
strict set of warnings.

The PR adds
```
  "-Wsuggest-override"
  "-Winconsistent-missing-override"
 ```
 to the CLANG_ONLY_WARNINGS.  This exposes a relatively small number of places where method overrides did not use the "override" keyword.  The PR fixes those.
 
(In cmd_util.h, I also made the *_CMD macros be uniform in not ending the class they define with a semicolon; the invocation of the macro can add the semicolon.)
This commit is contained in:
davedets 2026-06-18 12:36:14 -07:00 committed by GitHub
parent 3bf4d2b53d
commit 99a8a922ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 59 additions and 38 deletions

View file

@ -20,6 +20,9 @@ set(CLANG_ONLY_WARNINGS
"-Wno-c++98-compat" "-Wno-c++98-compat"
"-Wno-c++98-compat-pedantic" "-Wno-c++98-compat-pedantic"
"-Wno-zero-length-array" "-Wno-zero-length-array"
"-Wc99-extensions"
"-Wsuggest-override"
"-Winconsistent-missing-override"
) )
set(MSVC_WARNINGS "/W3") set(MSVC_WARNINGS "/W3")

View file

@ -17,44 +17,50 @@ Notes:
--*/ --*/
#pragma once #pragma once
#define ATOMIC_CMD(CLS_NAME, NAME, DESCR, ACTION) \ #define ATOMIC_CMD(CLS_NAME, NAME, DESCR, ACTION) \
class CLS_NAME : public cmd { \
public: \
CLS_NAME():cmd(NAME) {} \
char const * get_usage() const override { return 0; } \
char const * get_descr(cmd_context & ctx) const override { \
return DESCR; \
} \
unsigned get_arity() const override { return 0; } \
void execute(cmd_context & ctx) override { ACTION } \
}
#define UNARY_CMD(CLS_NAME, NAME, USAGE, DESCR, ARG_KIND, ARG_TYPE, ACTION) \
class CLS_NAME : public cmd { \ class CLS_NAME : public cmd { \
public: \ public: \
CLS_NAME():cmd(NAME) {} \ CLS_NAME():cmd(NAME) {} \
virtual char const * get_usage() const { return 0; } \ char const * get_usage() const override { return USAGE; } \
virtual char const * get_descr(cmd_context & ctx) const { return DESCR; } \ char const * get_descr(cmd_context & ctx) const override { \
virtual unsigned get_arity() const { return 0; } \ return DESCR; \
virtual void execute(cmd_context & ctx) { ACTION } \ } \
}; unsigned get_arity() const override { return 1; } \
cmd_arg_kind next_arg_kind(cmd_context & ctx) const override { \
#define UNARY_CMD(CLS_NAME, NAME, USAGE, DESCR, ARG_KIND, ARG_TYPE, ACTION) \ return ARG_KIND; \
class CLS_NAME : public cmd { \ } \
public: \ void set_next_arg(cmd_context & ctx, ARG_TYPE arg) override { ACTION } \
CLS_NAME():cmd(NAME) {} \
virtual char const * get_usage() const { return USAGE; } \
virtual char const * get_descr(cmd_context & ctx) const { return DESCR; } \
virtual unsigned get_arity() const { return 1; } \
virtual cmd_arg_kind next_arg_kind(cmd_context & ctx) const { return ARG_KIND; } \
virtual void set_next_arg(cmd_context & ctx, ARG_TYPE arg) { ACTION } \
} }
// Macro for creating commands where the first argument is a symbol // Macro for creating commands where the first argument is a symbol
// The second argument cannot be a symbol // The second argument cannot be a symbol
#define BINARY_SYM_CMD(CLS_NAME, NAME, USAGE, DESCR, ARG_KIND, ARG_TYPE, ACTION) \ #define BINARY_SYM_CMD(CLS_NAME, NAME, USAGE, DESCR, ARG_KIND, ARG_TYPE, ACTION) \
class CLS_NAME : public cmd { \ class CLS_NAME : public cmd { \
symbol m_sym; \ symbol m_sym; \
public: \ public: \
CLS_NAME():cmd(NAME) {} \ CLS_NAME():cmd(NAME) {} \
virtual char const * get_usage() const { return USAGE; } \ char const * get_usage() const override { return USAGE; } \
virtual char const * get_descr(cmd_context & ctx) const { return DESCR; } \ char const * get_descr(cmd_context & ctx) const override { return DESCR; } \
virtual unsigned get_arity() const { return 2; } \ unsigned get_arity() const override { return 2; } \
virtual void prepare(cmd_context & ctx) { m_sym = symbol::null; } \ void prepare(cmd_context & ctx) override { m_sym = symbol::null; } \
virtual cmd_arg_kind next_arg_kind(cmd_context & ctx) const { \ cmd_arg_kind next_arg_kind(cmd_context & ctx) const override { \
return m_sym == symbol::null ? CPK_SYMBOL : ARG_KIND; \ return m_sym == symbol::null ? CPK_SYMBOL : ARG_KIND; \
} \ } \
virtual void set_next_arg(cmd_context & ctx, symbol const & s) { m_sym = s; } \ void set_next_arg(cmd_context & ctx, symbol const & s) override { m_sym = s; } \
virtual void set_next_arg(cmd_context & ctx, ARG_TYPE arg) { ACTION } \ void set_next_arg(cmd_context & ctx, ARG_TYPE arg) override { ACTION } \
}; }
class ast; class ast;

View file

@ -580,7 +580,7 @@ namespace lp {
const lar_term* m_t; const lar_term* m_t;
undo_add_term(imp& s, const lar_term* t) : m_s(s), m_t(t) {} undo_add_term(imp& s, const lar_term* t) : m_s(s), m_t(t) {}
void undo() { void undo() override {
m_s.undo_add_term_method(m_t); m_s.undo_add_term_method(m_t);
} }
}; };

View file

@ -60,6 +60,14 @@ std::ostream& operator<<(std::ostream& out, const row_strip<T>& r) {
return out << "\n"; return out << "\n";
} }
// Below, static_matrix has a superclass when Z3DEBUG is set, and some
// methods are overrides in that case.
#ifdef Z3DEBUG
#define DEBUG_OVERRIDE override
#else
#define DEBUG_OVERRIDE
#endif
// each assignment for this matrix should be issued only once!!! // each assignment for this matrix should be issued only once!!!
template <typename T, typename X> template <typename T, typename X>
class static_matrix class static_matrix
@ -119,9 +127,13 @@ public:
void init_empty_matrix(unsigned m, unsigned n); void init_empty_matrix(unsigned m, unsigned n);
unsigned row_count() const { return static_cast<unsigned>(m_rows.size()); } unsigned row_count() const DEBUG_OVERRIDE {
return static_cast<unsigned>(m_rows.size());
}
unsigned column_count() const { return static_cast<unsigned>(m_columns.size()); } unsigned column_count() const DEBUG_OVERRIDE {
return static_cast<unsigned>(m_columns.size());
}
unsigned lowest_row_in_column(unsigned col); unsigned lowest_row_in_column(unsigned col);
@ -197,7 +209,7 @@ public:
void cross_out_row_from_column(unsigned col, unsigned k); void cross_out_row_from_column(unsigned col, unsigned k);
T get_elem(unsigned i, unsigned j) const; T get_elem(unsigned i, unsigned j) const DEBUG_OVERRIDE;
unsigned number_of_non_zeroes_in_column(unsigned j) const { return static_cast<unsigned>(m_columns[j].size()); } unsigned number_of_non_zeroes_in_column(unsigned j) const { return static_cast<unsigned>(m_columns[j].size()); }
@ -218,8 +230,8 @@ public:
#ifdef Z3DEBUG #ifdef Z3DEBUG
unsigned get_number_of_rows() const { return row_count(); } unsigned get_number_of_rows() const { return row_count(); }
unsigned get_number_of_columns() const { return column_count(); } unsigned get_number_of_columns() const { return column_count(); }
virtual void set_number_of_rows(unsigned /*m*/) { } void set_number_of_rows(unsigned /*m*/) override { }
virtual void set_number_of_columns(unsigned /*n*/) { } void set_number_of_columns(unsigned /*n*/) override { }
#endif #endif
T get_balance() const; T get_balance() const;

View file

@ -185,12 +185,12 @@ class asserted_formulas {
public: \ public: \
FUNCTOR m_functor; \ FUNCTOR m_functor; \
NAME(asserted_formulas& af):simplify_fmls(af, MSG), m_functor ARG {} \ NAME(asserted_formulas& af):simplify_fmls(af, MSG), m_functor ARG {} \
virtual void simplify(justified_expr const& j, expr_ref& n, proof_ref& p) { \ void simplify(justified_expr const& j, expr_ref& n, proof_ref& p) override { \
m_functor(j.fml(), n, p); \ m_functor(j.fml(), n, p); \
} \ } \
virtual void post_op() { if (REDUCE) af.reduce_and_solve(); } \ void post_op() override { if (REDUCE) af.reduce_and_solve(); } \
virtual bool should_apply() const { return APP; } \ bool should_apply() const override { return APP; } \
}; \ };
#define MK_SIMPLIFIERF(NAME, FUNCTOR, MSG, APP, REDUCE) MK_SIMPLIFIERA(NAME, FUNCTOR, MSG, APP, (af.m), REDUCE) #define MK_SIMPLIFIERF(NAME, FUNCTOR, MSG, APP, REDUCE) MK_SIMPLIFIERA(NAME, FUNCTOR, MSG, APP, (af.m), REDUCE)