From 5773833af8d8644bb59e664fe068c93b825974e3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 12 Jun 2023 05:51:26 +0200 Subject: Hack around GCC 13 -Wdangling-reference false positives See GCC bugs 107532, 110213. --- libbuild2/adhoc-rule-buildscript.cxx | 5 +++-- libbuild2/algorithm.cxx | 2 +- libbuild2/algorithm.hxx | 2 +- libbuild2/variable.hxx | 12 ++++++------ libbuild2/variable.ixx | 12 ++++++------ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx index a67b07b..61a9e21 100644 --- a/libbuild2/adhoc-rule-buildscript.cxx +++ b/libbuild2/adhoc-rule-buildscript.cxx @@ -718,10 +718,11 @@ namespace build2 // for (dir_path& d: p.second) { + dir_path o; string n; // For GCC 13 -Wdangling-reference. const fsdir& dt (search (t, move (d), - dir_path (), - string (), nullptr, nullptr)); + move (o), + move (n), nullptr, nullptr)); match_sync (a, dt); pts.push_back (prerequisite_target (&dt, true /* adhoc */)); } diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index 3c0da3b..4db3d72 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -122,7 +122,7 @@ namespace build2 } const target& - search (const target& t, name n, const scope& s, const target_type* tt) + search (const target& t, name&& n, const scope& s, const target_type* tt) { assert (t.ctx.phase == run_phase::match); diff --git a/libbuild2/algorithm.hxx b/libbuild2/algorithm.hxx index 216ec4b..8bdf737 100644 --- a/libbuild2/algorithm.hxx +++ b/libbuild2/algorithm.hxx @@ -164,7 +164,7 @@ namespace build2 // argument. // LIBBUILD2_SYMEXPORT const target& - search (const target&, name, const scope&, const target_type* = nullptr); + search (const target&, name&&, const scope&, const target_type* = nullptr); // Note: returns NULL for unknown target types. Note that unlike the above // version, these ones can be called during the load and execute phases. diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index 3220a62..2d7f8ba 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -465,37 +465,37 @@ namespace build2 template T& cast (value&); template T&& cast (value&&); template const T& cast (const value&); - template const T& cast (const lookup&); + template const T& cast (lookup); // As above but returns NULL if the value is NULL (or not defined, in // case of lookup). // template T* cast_null (value&); template const T* cast_null (const value&); - template const T* cast_null (const lookup&); + template const T* cast_null (lookup); // As above but returns empty value if the value is NULL (or not defined, in // case of lookup). // template const T& cast_empty (const value&); - template const T& cast_empty (const lookup&); + template const T& cast_empty (lookup); // As above but returns the specified default if the value is NULL (or not // defined, in case of lookup). Note that the return is by value, not by // reference. // template T cast_default (const value&, const T&); - template T cast_default (const lookup&, const T&); + template T cast_default (lookup, const T&); // As above but returns false/true if the value is NULL (or not defined, // in case of lookup). Note that the template argument is only for // documentation and should be bool (or semantically compatible). // template T cast_false (const value&); - template T cast_false (const lookup&); + template T cast_false (lookup); template T cast_true (const value&); - template T cast_true (const lookup&); + template T cast_true (lookup); // Assign value type to the value. The variable is optional and is only used // for diagnostics. diff --git a/libbuild2/variable.ixx b/libbuild2/variable.ixx index c7b1f35..51c35fd 100644 --- a/libbuild2/variable.ixx +++ b/libbuild2/variable.ixx @@ -224,7 +224,7 @@ namespace build2 template inline const T& - cast (const lookup& l) + cast (lookup l) { return cast (*l); } @@ -245,7 +245,7 @@ namespace build2 template inline const T* - cast_null (const lookup& l) + cast_null (lookup l) { return l ? &cast (*l) : nullptr; } @@ -259,7 +259,7 @@ namespace build2 template inline const T& - cast_empty (const lookup& l) + cast_empty (lookup l) { return l ? cast (l) : value_traits::empty_instance; } @@ -273,7 +273,7 @@ namespace build2 template inline T - cast_default (const lookup& l, const T& d) + cast_default (lookup l, const T& d) { return l ? cast (l) : d; } @@ -287,7 +287,7 @@ namespace build2 template inline T - cast_false (const lookup& l) + cast_false (lookup l) { return l && cast (l); } @@ -301,7 +301,7 @@ namespace build2 template inline T - cast_true (const lookup& l) + cast_true (lookup l) { return !l || cast (l); } -- cgit v1.1