Everywhere: Warn on function definitions without prototypes

If no header includes the prototype of a function, then it cannot be
used from outside the translation unit it was defined in. In that case,
it should be marked as `static`, in order to avoid possible ODR
problems, unnecessary exported symbols, and allow the compiler to better
optimize those.

If this warning triggers in a function defined in a header, `inline`
needs to be added, otherwise if the header is included in more than one
TU, it will fail to link with a duplicate definition error.

The reason this diff got so big is that Lagom-only code wasn't built
with this flag even in Serenity times.
This commit is contained in:
Daniel Bertalan 2024-07-14 18:29:33 +02:00
parent 7fe82a1cda
commit c62240aa80
Notes: sideshowbarker 2024-07-18 08:27:14 +09:00
24 changed files with 146 additions and 97 deletions

View file

@ -13,7 +13,7 @@
#include <LibCore/File.h>
#include <ctype.h>
String title_casify(StringView dashy_name)
inline String title_casify(StringView dashy_name)
{
auto parts = dashy_name.split_view('-');
StringBuilder builder;
@ -28,7 +28,7 @@ String title_casify(StringView dashy_name)
return MUST(builder.to_string());
}
String camel_casify(StringView dashy_name)
inline String camel_casify(StringView dashy_name)
{
auto parts = dashy_name.split_view('-');
StringBuilder builder;
@ -49,14 +49,14 @@ String camel_casify(StringView dashy_name)
return MUST(builder.to_string());
}
String snake_casify(StringView dashy_name)
inline String snake_casify(StringView dashy_name)
{
// FIXME: We don't really need to convert dashy_name to a String first, but currently
// all the `replace` functions that take a StringView return ByteString.
return MUST(MUST(String::from_utf8(dashy_name)).replace("-"sv, "_"sv, ReplaceMode::All));
}
ErrorOr<JsonValue> read_entire_file_as_json(StringView filename)
inline ErrorOr<JsonValue> read_entire_file_as_json(StringView filename)
{
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Read));
auto json_size = TRY(file->size());