From 8aee78c8d0eb06334571e596f6fbdf7ed5756f0c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 8 Feb 2017 09:24:07 +0200 Subject: Tighten target constness further --- build2/cli/rule.cxx | 2 +- build2/cli/target | 39 ++++++++++++--------------------------- build2/cli/target.cxx | 9 +++++++-- 3 files changed, 20 insertions(+), 30 deletions(-) (limited to 'build2/cli') diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx index 7928c5c..ba4963e 100644 --- a/build2/cli/rule.cxx +++ b/build2/cli/rule.cxx @@ -207,7 +207,7 @@ namespace build2 static void append_extension (cstrings& args, - path_target& t, + const path_target& t, const char* option, const char* default_extension) { diff --git a/build2/cli/target b/build2/cli/target index f4ab7e7..c10e4b8 100644 --- a/build2/cli/target +++ b/build2/cli/target @@ -26,37 +26,22 @@ namespace build2 virtual const target_type& dynamic_type () const {return static_type;} }; - class cli_cxx: public mtime_target + // Standard layout type compatible with target*[3]. + // + struct cli_cxx_members { - public: - union - { - // It is theoretically possible that the compiler will add - // padding between the members of this struct. This would - // mean that the optimal alignment for a pointer is greater - // than its size (and that an array of pointers is sub- - // optimally aligned). We will deal with such a beast of - // an architecture when we see it. - // - struct - { - cxx::hxx* h; - cxx::cxx* c; - cxx::ixx* i; - }; - target* m[3] /*= {nullptr, nullptr, nullptr}*/; // @@ GCC 4.8 - }; - - //using mtime_target::mtime_target; // @@ GCC 4.8 + const_ptr h = nullptr; + const_ptr c = nullptr; + const_ptr i = nullptr; + }; - cli_cxx (dir_path d, dir_path o, string n) - : mtime_target (move (d), move (o), move (n)) - { - m[0] = m[1] = m[2] = nullptr; - } + class cli_cxx: public mtime_target, public cli_cxx_members + { + public: + using mtime_target::mtime_target; virtual group_view - group_members (action_type) const; + group_members (action_type); virtual timestamp load_mtime () const; diff --git a/build2/cli/target.cxx b/build2/cli/target.cxx index 48dc95b..200f6f0 100644 --- a/build2/cli/target.cxx +++ b/build2/cli/target.cxx @@ -32,10 +32,15 @@ namespace build2 // cli.cxx // group_view cli_cxx:: - group_members (action_type) const + group_members (action_type) { + static_assert (offsetof (cli_cxx_members, i) - + offsetof (cli_cxx_members, h) == sizeof (target*) * 2, + "member layout incompatible with array"); + return h != nullptr - ? group_view {m, (i != nullptr ? 3U : 2U)} + ? group_view {reinterpret_cast (&h), + (i != nullptr ? 3U : 2U)} : group_view {nullptr, 0}; } -- cgit v1.1