From c8810465be8237ceb3ef96e7512a4762756584ff Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Feb 2024 10:02:44 +0200 Subject: Diagnose instead of asserting ad hoc group member not already existing Fixes GH issue #365. --- libbuild2/algorithm.cxx | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index 7fde2a9..3d8b89c 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -375,29 +375,26 @@ namespace build2 if (*mp != nullptr) // Might already be there. return **mp; - target* m (nullptr); - { - pair r ( - t.ctx.targets.insert_locked (tt, - move (dir), - move (out), - move (n), - move (ext), - target_decl::implied, - trace, - true /* skip_find */)); - - if (r.second) // Inserted. - { - m = &r.first; - m->group = &t; - } - } + pair r ( + t.ctx.targets.insert_locked (tt, + move (dir), + move (out), + move (n), + move (ext), + target_decl::implied, + trace, + true /* skip_find */)); + + target& m (r.first); - assert (m != nullptr); - *mp = m; + if (!r.second) + fail << "target " << m << " already exists and cannot be made " + << "ad hoc member of group " << t; + + m.group = &t; + *mp = &m; - return *m; + return m; }; pair -- cgit v1.1