eggs-cpp / variant

Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union.
http://eggs-cpp.github.io/variant/
Boost Software License 1.0
138 stars 27 forks source link

variant<...> is not a literal type #16

Closed robertramey closed 8 years ago

robertramey commented 8 years ago

The following two line program provokes and error message in the latest version of Clang with Xcode.

#include <eggs/variant.hpp>
static_assert(std::is_literal_type<eggs::variant<int, Dtor>>::value, "variant is not a literal type");

This prevents me from using eggs/variant in a struct created by a constexpr function. My understanding was that one of the motivations of the eggs/variant variant is to facilitate the usage of variants in constexpr functions.

Robert Ramey

viboes commented 8 years ago

What is Dtor? If Dtor means a class with a non-trivial destructor, it makes it non-literal

K-ballo commented 8 years ago

[ constexpr support was not a motivating force for Eggs.Variant, it just comes with the job ]

The two line snippet fails to compile because Dtor is not declared. However, I am going to assume that it is referring to the utility class used in tests to track that destructors are actually caled. As @viboes explains, Dtor is a class with a non-trivial destructor, so std::is_literal_type<Dtor>::value yields false which makes the error expected:

Given the current language rules, a literal variant requires all member types to be literal types. Once CWG2096 is applied, the rules will be relaxed to at least one member being a literal type, while the requirement for a trivial destructor would still mandate all members be trivially destructible.

So in short, Dtor will never be a member of a literal variant.