diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-10-14 14:05:46 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-15 01:26:14 +0200 |
commit | d007337d97189facc8ad1b661ceabf06bfe7e5bc (patch) | |
tree | 6d322de59dfaf1cd0bd8abac9718ef58cce93f87 | |
parent | db23e2d5460482591abee4a693035cefde9ab962 (diff) | |
download | serenity-d007337d97189facc8ad1b661ceabf06bfe7e5bc.zip |
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").
-rw-r--r-- | AK/Variant.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/AK/Variant.h b/AK/Variant.h index 30856ca9a9..8962b7ee0a 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -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; |