3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-21 17:44:43 +00:00

Add [[nodiscard]] to AST factory functions and modernize iterator loops (#8143)

* Initial plan

* Add [[nodiscard]] to AST factory functions and modernize iterator loops

- Added [[nodiscard]] attribute to key factory functions in ast.h:
  - All mk_app() variants for creating application nodes
  - All mk_func_decl() variants for creating function declarations
  - All mk_const() variants for creating constants
  - All mk_sort() variants for creating sorts
  - mk_var() for creating variables
  - mk_quantifier(), mk_forall(), mk_exists(), mk_lambda() for quantifiers
  - mk_label(), mk_pattern() and related functions

- Converted iterator loops to range-based for loops in:
  - src/util/region.cpp: pop_scope()
  - src/util/dec_ref_util.h: dec_ref_key_values(), dec_ref_keys(), dec_ref_values()
  - src/util/mpf.h: dispose()
  - src/util/numeral_buffer.h: reset()

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Modernize additional iterator loops to range-based for loops

- Converted iterator loops to range-based for loops in:
  - src/api/api_ast_map.cpp: Z3_ast_map_keys() and Z3_ast_map_to_string()
  - src/api/c++/z3++.h: optimize copy constructor and add() method
  - src/opt/wmax.cpp: mk_assumptions()

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Revert changes to z3++.h for C++ version compatibility

Revert the range-based for loop changes in src/api/c++/z3++.h to maintain
compatibility with older C++ versions that users may rely on. The C++ API
wrapper must support down-level C++ standards for backward compatibility.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Trigger CI build

[skip ci] is not used to ensure CI runs

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-11 09:58:25 -08:00 committed by GitHub
parent d29fc3eef3
commit 6c90b7ec3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 89 additions and 104 deletions

View file

@ -129,9 +129,8 @@ namespace opt {
void mk_assumptions(expr_ref_vector& asms) {
ptr_vector<expr> _asms;
obj_map<expr, rational>::iterator it = m_weights.begin(), end = m_weights.end();
for (; it != end; ++it) {
_asms.push_back(it->m_key);
for (auto const& kv : m_weights) {
_asms.push_back(kv.m_key);
}
compare_asm comp(*this);
std::sort(_asms.begin(),_asms.end(), comp);