Skip to content

Commit

Permalink
Fix static ctor order bug that appeared with clang 3.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Jan 26, 2014
1 parent 5af00c6 commit 7953032
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/foreign.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// -*- compile-command: "make foreign && ./foreign" -*-

// clang++ -g -std=c++11 -I../include ../src/multi_methods.cpp foreign.cpp -o foreign && ./foreign
// foreign.cpp
// Copyright (c) 2013 Jean-Louis Leroy
// Distributed under the Boost Software License, Version 1.0. (See
Expand Down
18 changes: 10 additions & 8 deletions src/multi_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ namespace yorel {

void mm_class::add_to_initialize(mm_class* pc) {
YOREL_MM_TRACE(cout << "add to initialize: " << pc << endl);
assert(pc->is_root());

if (!to_initialize) {
to_initialize.reset(new unordered_set<mm_class*>);
Expand Down Expand Up @@ -248,7 +247,11 @@ namespace yorel {
void initialize() {
while (mm_class::to_initialize) {
auto pc = *mm_class::to_initialize->begin();
hierarchy_initializer::initialize(*pc);
if (pc->is_root()) {
hierarchy_initializer::initialize(*pc);
} else {
mm_class::remove_from_initialize(pc);
}
}

while (multi_method_base::to_initialize) {
Expand Down Expand Up @@ -284,7 +287,7 @@ namespace yorel {

void mm_class::add_multi_method(multi_method_base* pm, int arg) {
rooted_here.push_back(mmref { pm, arg });
add_to_initialize(root);
add_to_initialize(this);
}

void mm_class::remove_multi_method(multi_method_base* pm) {
Expand All @@ -311,11 +314,10 @@ namespace yorel {

multi_method_base::multi_method_base(const vector<mm_class*>& v) : vargs(v) {
int i = 0;
for_each(vargs.begin(), vargs.end(),
[&](mm_class* pc) {
YOREL_MM_TRACE(cout << "add mm rooted in " << pc->ti.name() << " argument " << i << "\n");
pc->add_multi_method(this, i++);
});
for (auto pc : vargs) {
YOREL_MM_TRACE(cout << "add mm rooted in " << pc->ti.name() << " argument " << i << "\n");
pc->add_multi_method(this, i++);
}
slots.resize(v.size());
}

Expand Down

0 comments on commit 7953032

Please sign in to comment.