From 96c59ff30a2dbe2cc441024c81caaf79823441ac Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 15 Nov 2019 09:23:39 +0200 Subject: Fix bug in cc::parser location storage --- libbuild2/types.hxx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'libbuild2/types.hxx') diff --git a/libbuild2/types.hxx b/libbuild2/types.hxx index bedcf1a..8566c50 100644 --- a/libbuild2/types.hxx +++ b/libbuild2/types.hxx @@ -311,12 +311,12 @@ namespace build2 // Diagnostics location. // + // Note that location maintains a shallow reference to path. Zero lines or + // columns are not printed. + // class location { public: - // Note that location maintains a shallow reference to path. Zero lines - // or columns are not printed. - // explicit location (const path* f = nullptr, uint64_t l = 0, uint64_t c = 0) : file (f), line (l), column (c) {} @@ -333,6 +333,27 @@ namespace build2 uint64_t column; }; + // Similar (and implicit-convertible) to the above but stores a copy of the + // path. + // + class location_value: public location + { + public: + location_value () = default; + + explicit + location_value (const location& l) + : location (path_name (file_value, l.file.name), l.line, l.column), + file_value (l.file.path != nullptr ? *l.file.path : path ()) {} + + explicit + location_value (location&& l) + : location (path_name (file_value, move (l.file.name)), l.line, l.column), + file_value (l.file.path != nullptr ? *l.file.path : path ()) {} + + path file_value; + }; + // See context. // enum class run_phase {load, match, execute}; -- cgit v1.1