AK: Explictly disallow lvalue reference types within Variant

This prevents an ICE with GCC trying to declare e.g. Variant<String&>.

Using a concept is a bit overkill here, but clang otherwise trips over
the friendship declaration to other Variant types:

    template<typename... NewTs>
    friend struct Variant;

Without using a concept, clang believes this is re-declaring the Variant
type with differing requirements ("error: requires clause differs in
template redeclaration").
This commit is contained in:
Timothy Flynn 2022-10-14 14:05:46 -04:00 committed by Linus Groh
parent db23e2d546
commit d007337d97
Notes: sideshowbarker 2024-07-18 01:43:16 +09:00

View file

@ -215,7 +215,10 @@ namespace AK {
struct Empty {
};
template<typename... Ts>
template<typename T>
concept NotLvalueReference = !IsLvalueReference<T>;
template<NotLvalueReference... Ts>
struct Variant
: public Detail::MergeAndDeduplicatePacks<Detail::VariantConstructors<Ts, Variant<Ts...>>...> {
private:
@ -244,7 +247,7 @@ public:
{
}
template<typename... NewTs>
template<NotLvalueReference... NewTs>
friend struct Variant;
Variant() requires(!can_contain<Empty>()) = delete;