AK+Everywhere: Delete Variant's default constructor

This was exposed to the user by mistake, and even accumulated a bunch of
users that didn't blow up out of sheer luck.
This commit is contained in:
Ali Mohammad Pur 2021-08-13 17:31:39 +04:30
parent 90e6b9d453
commit 15f95220ae
6 changed files with 29 additions and 11 deletions

View file

@ -210,6 +210,8 @@ public:
template<typename... NewTs>
friend struct Variant;
Variant() = delete;
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
Variant(const Variant&) requires(!(IsCopyConstructible<Ts> && ...)) = delete;
Variant(const Variant&) = default;

View file

@ -1556,7 +1556,7 @@ bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_mini
}
if (unicode) {
PropertyEscape property {};
PropertyEscape property { Empty {} };
bool negated = false;
if (parse_unicode_property_escape(property, negated)) {
@ -1575,7 +1575,8 @@ bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_mini
compares.empend(CompareTypeAndValuePair { CharacterCompareType::ScriptExtension, (ByteCodeValueType)script.script });
else
compares.empend(CompareTypeAndValuePair { CharacterCompareType::Script, (ByteCodeValueType)script.script });
});
},
[](Empty&) { VERIFY_NOT_REACHED(); });
stack.insert_bytecode_compare_values(move(compares));
match_length_minimum += 1;
return true;
@ -1818,7 +1819,7 @@ bool ECMA262Parser::parse_nonempty_class_ranges(Vector<CompareTypeAndValuePair>&
if (try_skip("-"))
return { CharClassRangeElement { .code_point = '-', .is_character_class = false } };
PropertyEscape property {};
PropertyEscape property { Empty {} };
bool negated = false;
if (parse_unicode_property_escape(property, negated)) {
return property.visit(
@ -1833,7 +1834,8 @@ bool ECMA262Parser::parse_nonempty_class_ranges(Vector<CompareTypeAndValuePair>&
return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script_extension = true };
else
return CharClassRangeElement { .script = script.script, .is_negated = negated, .is_character_class = true, .is_script = true };
});
},
[](Empty&) -> CharClassRangeElement { VERIFY_NOT_REACHED(); });
}
}
@ -1983,7 +1985,8 @@ bool ECMA262Parser::parse_unicode_property_escape(PropertyEscape& property, bool
return true;
},
[](Unicode::GeneralCategory) { return true; },
[](Script) { return true; });
[](Script) { return true; },
[](Empty&) -> bool { VERIFY_NOT_REACHED(); });
}
StringView ECMA262Parser::read_capture_group_specifier(bool take_starting_angle_bracket)

View file

@ -218,7 +218,7 @@ private:
Unicode::Script script {};
bool is_extension { false };
};
using PropertyEscape = Variant<Unicode::Property, Unicode::GeneralCategory, Script>;
using PropertyEscape = Variant<Unicode::Property, Unicode::GeneralCategory, Script, Empty>;
Optional<PropertyEscape> read_unicode_property_escape();
bool parse_pattern(ByteCode&, size_t&, bool unicode, bool named);

View file

@ -10,11 +10,13 @@
namespace SQL {
Value::Value(SQLType sql_type)
: m_impl(0)
{
setup(sql_type);
}
Value::Value(SQLType sql_type, ByteBuffer& buffer, size_t& offset)
: m_impl(0)
{
setup(sql_type);
m_deserialize(buffer, offset);
@ -22,6 +24,7 @@ Value::Value(SQLType sql_type, ByteBuffer& buffer, size_t& offset)
}
Value::Value(Value const& other)
: m_impl(0)
{
setup(other.type());
m_is_null = other.is_null();

View file

@ -102,7 +102,7 @@ private:
SQLType m_type { SQLType::Text };
bool m_is_null { true };
Variant<String, int, double> m_impl {};
Variant<String, int, double> m_impl;
};
}

View file

@ -2197,7 +2197,10 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(ParsingContex
OwnPtr<CalculatedStyleValue::CalcProductPartWithOperator> Parser::parse_calc_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
{
auto product_with_operator = make<CalculatedStyleValue::CalcProductPartWithOperator>();
// Note: The default value is not used or passed around.
auto product_with_operator = make<CalculatedStyleValue::CalcProductPartWithOperator>(
CalculatedStyleValue::CalcProductPartWithOperator::Multiply,
CalculatedStyleValue::CalcNumberValue(0));
tokens.skip_whitespace();
@ -2232,7 +2235,10 @@ OwnPtr<CalculatedStyleValue::CalcProductPartWithOperator> Parser::parse_calc_pro
OwnPtr<CalculatedStyleValue::CalcNumberProductPartWithOperator> Parser::parse_calc_number_product_part_with_operator(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
{
auto number_product_with_operator = make<CalculatedStyleValue::CalcNumberProductPartWithOperator>();
// Note: The default value is not used or passed around.
auto number_product_with_operator = make<CalculatedStyleValue::CalcNumberProductPartWithOperator>(
CalculatedStyleValue::CalcNumberProductPartWithOperator::Multiply,
CalculatedStyleValue::CalcNumberValue(0));
tokens.skip_whitespace();
@ -2263,7 +2269,9 @@ OwnPtr<CalculatedStyleValue::CalcNumberProductPartWithOperator> Parser::parse_ca
OwnPtr<CalculatedStyleValue::CalcNumberProduct> Parser::parse_calc_number_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
{
auto calc_number_product = make<CalculatedStyleValue::CalcNumberProduct>();
auto calc_number_product = make<CalculatedStyleValue::CalcNumberProduct>(
CalculatedStyleValue::CalcNumberValue(0),
NonnullOwnPtrVector<CalculatedStyleValue::CalcNumberProductPartWithOperator> {});
auto first_calc_number_value_or_error = parse_calc_number_value(context, tokens);
if (!first_calc_number_value_or_error.has_value())
@ -2348,7 +2356,9 @@ Optional<CalculatedStyleValue::CalcNumberValue> Parser::parse_calc_number_value(
OwnPtr<CalculatedStyleValue::CalcProduct> Parser::parse_calc_product(ParsingContext const& context, TokenStream<StyleComponentValueRule>& tokens)
{
auto calc_product = make<CalculatedStyleValue::CalcProduct>();
auto calc_product = make<CalculatedStyleValue::CalcProduct>(
CalculatedStyleValue::CalcValue(0),
NonnullOwnPtrVector<CalculatedStyleValue::CalcProductPartWithOperator> {});
auto first_calc_value_or_error = parse_calc_value(context, tokens);
if (!first_calc_value_or_error.has_value())