1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

AK: Simplify constructors and conversions from nullptr_t

Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
This commit is contained in:
Lenny Maiorani 2021-01-10 16:29:28 -07:00 committed by Andreas Kling
parent 9dc44bf8c4
commit e6f907a155
105 changed files with 300 additions and 244 deletions

View file

@ -67,7 +67,7 @@ OwnPtr<Messages::LaunchServer::OpenURLResponse> ClientConnection::handle(const M
if (!allowed) {
// You are not on the list, go home!
did_misbehave(String::formatted("Client requested a combination of handler/URL that was not on the list: '{}' with '{}'", request.handler_name(), request.url()).characters());
return nullptr;
return {};
}
}
@ -94,12 +94,12 @@ OwnPtr<Messages::LaunchServer::AddAllowedURLResponse> ClientConnection::handle(c
{
if (m_allowlist_is_sealed) {
did_misbehave("Got request to add more allowed handlers after list was sealed");
return nullptr;
return {};
}
if (!request.url().is_valid()) {
did_misbehave("Got request to allow invalid URL");
return nullptr;
return {};
}
m_allowlist.empend(String(), false, Vector<URL> { request.url() });
@ -111,12 +111,12 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithAnyURLResponse> ClientConnec
{
if (m_allowlist_is_sealed) {
did_misbehave("Got request to add more allowed handlers after list was sealed");
return nullptr;
return {};
}
if (request.handler_name().is_empty()) {
did_misbehave("Got request to allow empty handler name");
return nullptr;
return {};
}
m_allowlist.empend(request.handler_name(), true, Vector<URL>());
@ -128,17 +128,17 @@ OwnPtr<Messages::LaunchServer::AddAllowedHandlerWithOnlySpecificURLsResponse> Cl
{
if (m_allowlist_is_sealed) {
did_misbehave("Got request to add more allowed handlers after list was sealed");
return nullptr;
return {};
}
if (request.handler_name().is_empty()) {
did_misbehave("Got request to allow empty handler name");
return nullptr;
return {};
}
if (request.urls().is_empty()) {
did_misbehave("Got request to allow empty URL list");
return nullptr;
return {};
}
m_allowlist.empend(request.handler_name(), false, request.urls());
@ -150,7 +150,7 @@ OwnPtr<Messages::LaunchServer::SealAllowlistResponse> ClientConnection::handle(c
{
if (m_allowlist_is_sealed) {
did_misbehave("Got more than one request to seal the allowed handlers list");
return nullptr;
return {};
}
return make<Messages::LaunchServer::SealAllowlistResponse>();