summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-10-14 14:05:46 -0400
committerLinus Groh <mail@linusgroh.de>2022-10-15 01:26:14 +0200
commitd007337d97189facc8ad1b661ceabf06bfe7e5bc (patch)
tree6d322de59dfaf1cd0bd8abac9718ef58cce93f87 /AK
parentdb23e2d5460482591abee4a693035cefde9ab962 (diff)
downloadserenity-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").
Diffstat (limited to 'AK')
-rw-r--r--AK/Variant.h7
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;