Skip to content

Commit

Permalink
Fix unused variables and variable with a undefined value.
Browse files Browse the repository at this point in the history
The latter isn't actually used anywhere before it's declared, and
an assert would enforce this, but it would still trigger a warning.
Now it's set to a value that's never used, and the assert has been
replaced with an exception so it can't be used in a release build
either. (optima.h)
  • Loading branch information
kristomu committed Aug 31, 2024
1 parent d419c10 commit 5db89cb
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/interpreter/rank_order.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ bool rank_order_int::is_this_format(const std::vector<std::string> &
// Possible todo later: more sophisticated checking, such as no rank
// symbols before a :.

int alnums_seen = 0;

for (size_t line = 0; line < inputs.size(); ++line) {
for (size_t sec = 0; sec < inputs[line].size(); ++sec) {
bool accepted = false;
Expand All @@ -43,7 +41,6 @@ bool rank_order_int::is_this_format(const std::vector<std::string> &
// "Write-In".
default:
if (isprint(inputs[line][sec])) {
++ alnums_seen;
accepted = true;
} else {
accepted = false;
Expand Down
4 changes: 1 addition & 3 deletions src/main/test_strategy_brute_detail.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void test_strategy(std::shared_ptr<const election_method> to_test,
}


int strategy_worked = 0, strategy_failed = 0;
int strategy_worked = 0;
int i;
int total_test_attempts = 0;

Expand All @@ -161,8 +161,6 @@ void test_strategy(std::shared_ptr<const election_method> to_test,
// The total number of tests actually performed is retrieved later.
if (st.simulate(true) == 0) {
++strategy_worked;
} else {
++strategy_failed;
}

if ((i & 63) == 63) {
Expand Down
10 changes: 9 additions & 1 deletion src/multiwinner/exhaustive/optima.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class exhaustive_optima {
}

exhaustive_optima() {
// We have to set a maximization direction as otherwise
// it will count as an undefined value and may trip compiler
// warnings. However, we never use this direction since
// opt_direction_set is false.
maximize = false;
opt_direction_set = false;

minimum = std::numeric_limits<double>::signaling_NaN();
Expand Down Expand Up @@ -74,7 +79,10 @@ class exhaustive_optima {
}

std::vector<size_t> get_optimal_solution() const {
assert(opt_direction_set);
if (!opt_direction_set) {
throw std::runtime_error("Exhaustive optima: Init bug! No direction"
" of optimization has been set.");
}
if (maximize) {
return get_maximum_solution();
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/singlewinner/experimental/disqelim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bool disqelim::disqualifies(int candidate,
power_set(continuing);

disqualified[candidate] = false;
int disqualifieds = count_trues(disqualified);

// For every subset of the continuing set:
// if the candidate is not in it, skip.
Expand Down Expand Up @@ -106,7 +105,6 @@ bool disqelim::disqualifies(int candidate,
}

disqualified[saved_cand] = false;
--disqualifieds;

// TODO: Return early if we don't disqualify
// anyone; no need to test further.
Expand Down
8 changes: 0 additions & 8 deletions src/singlewinner/gradual_c_b.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ std::pair<ordering, bool> gradual_cond_borda::elect_inner(const
election_t & papers, const std::vector<bool> & hopefuls,
int num_candidates, cache_map * cache, bool winner_only) const {

size_t num_hopefuls = 0;

for (bool x: hopefuls) {
if (x) {
++num_hopefuls;
}
}

cond_borda_matrix gcb(papers, num_candidates, CM_PAIRWISE_OPP,
cardinal, completion);
condmat gcond(papers, num_candidates, CM_PAIRWISE_OPP);
Expand Down
1 change: 1 addition & 0 deletions src/singlewinner/gradual_c_b.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <glpk.h>
#include <assert.h>

// This code needs a review; I think it may be buggy.

class gradual_cond_borda : public election_method {
private:
Expand Down

0 comments on commit 5db89cb

Please sign in to comment.