https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134

Arne Vogel <arvo at me dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arvo at me dot com

--- Comment #4 from Arne Vogel <arvo at me dot com> ---
@Jakub Jelinek: Returning empty structs (this affects empty tuples as well) can
be useful in templates. E.g.

struct empty_t {};

template<typename C>
void executeContext()
{
    auto savedState = C::prepare();
    C::execute();
    C::cleanup(std::move(savedState));
}

/*
 * Context which does not require saving state but should be compatible
 * with executeContext().
 */
struct StatelessContext
{
    static empty_t prepare();
    static void execute();
    static void cleanup(empty_t);
};

// Usage: executeContext<StatelessContext>();

Obviously, void does not work here *precisely* because executeContext saves
(i.e. uses) the return value. I have an example that makes more sense than the
above, but takes longer to explain. Anyway, I hope you get the idea.

A possible workaround is e.g. to use a dummy char instead. The documentation
says (slightly misleadingly, see below) empty structs in G++ are treated as
though they contained a single char. But this in turn may cause unwanted
interference e.g. with empty base optimization.

Reply via email to