aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/parser.cxx9
-rw-r--r--tests/define/buildfile2
2 files changed, 9 insertions, 2 deletions
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 7e07834..c632c80 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -888,7 +888,14 @@ namespace build2
// being called to construct a derived target. This can be used, for
// example, to decide whether to "link up" to the group.
//
- target* r (t.base->factory (t, move (d), move (n), e));
+ // One exception: if we are derived from a derived target type, the this
+ // logic will lead to infinite recursion. In this case get the ultimate
+ // base.
+ //
+ const target_type* bt (t.base);
+ for (; bt->factory == &derived_factory; bt = bt->base) ;
+
+ target* r (bt->factory (t, move (d), move (n), e));
r->derived_type = &t;
return r;
}
diff --git a/tests/define/buildfile b/tests/define/buildfile
index 55b9e92..d85fc57 100644
--- a/tests/define/buildfile
+++ b/tests/define/buildfile
@@ -9,6 +9,6 @@ foo{FOO}: # verify name is foo{FOO} and not file{FOO} with --verbose 6
#define foo: dir # already define in this scope
define bar: foo
-bar{BAR}: # verify name is bar{FOO} with --verbose 6
+bar{BAR}: # verify name is bar{BAR} with --verbose 6
./: