Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix small issue with std::sort calling a comparator that does not respect strict_weak_ordering #874

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions include/minizinc/flatten_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,17 @@ public:
std::vector<KeepAlive>& x;
CmpExpIdx(std::vector<KeepAlive>& x0) : x(x0) {}
bool operator()(int i, int j) const {
if (Expression::equal(x[i](), x[j]())) {
return false;
}
if (Expression::isa<Id>(x[i]()) && Expression::isa<Id>(x[j]()) &&
Expression::cast<Id>(x[i]())->idn() != -1 && Expression::cast<Id>(x[j]())->idn() != -1) {
return Expression::cast<Id>(x[i]())->idn() < Expression::cast<Id>(x[j]())->idn();
const long long int i_idn =
Expression::isa<Id>(x[i]()) ? Expression::cast<Id>(x[i]())->idn() : -1;
const long long int j_idn =
Expression::isa<Id>(x[j]()) ? Expression::cast<Id>(x[j]())->idn() : -1;
const bool i_is_valid_id = i_idn != -1;
const bool j_is_valid_id = j_idn != -1;
if (i_is_valid_id != j_is_valid_id) {
return i_is_valid_id > j_is_valid_id;
}
if (i_is_valid_id && j_is_valid_id) {
return i_idn < j_idn;
}
return x[i]() < x[j]();
}
Expand Down
2 changes: 2 additions & 0 deletions include/minizinc/htmlprinter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <utility>
#include <vector>

#include <minizinc/flatten_internal.hh>

namespace MiniZinc {

class Model;
Expand Down
4 changes: 4 additions & 0 deletions include/minizinc/statistics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#pragma once

#include <iterator>
#include <ios>

#include <minizinc/ast.hh>
#include <minizinc/prettyprinter.hh>

namespace MiniZinc {

Expand Down
6 changes: 6 additions & 0 deletions lib/parser.yxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

%code requires {
#include <minizinc/ast.hh>
}

%define api.pure

%parse-param {void *parm}
Expand All @@ -32,6 +36,8 @@ namespace MiniZinc{ class ParserLocation; }
#define YYMAXDEPTH 10000
#define YYINITDEPTH 10000

#include <vector>

#include <minizinc/parser.hh>
#include <minizinc/file_utils.hh>

Expand Down