Adds pedantic-error flag, work on making source more aligned with ISO C++
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-04-01 12:05:48 +02:00
parent 510fa60c0e
commit 219fbfc94e
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 37 additions and 35 deletions

View File

@ -5,7 +5,7 @@
std::string ExceptionHandler::_ArbutilsLastException = ""; std::string ExceptionHandler::_ArbutilsLastException = "";
/// @brief Returns a null-terminated C string to the last exception found. /// @brief Returns a null-terminated C string to the last exception found.
export const char* Arbutils_C_GetLastException() { return ExceptionHandler::GetLastException(); } export_func const char* Arbutils_C_GetLastException() { return ExceptionHandler::GetLastException(); }
#if !WINDOWS && SIGNAL_HANDLING #if !WINDOWS && SIGNAL_HANDLING
static ArbUt::SignalHandling sh; static ArbUt::SignalHandling sh;
@ -13,5 +13,5 @@ static ArbUt::SignalHandling sh;
export void Arbutils_C_SetSignalCallback(void (*callback)(const char*)) { sh.SetCallback(callback); } export void Arbutils_C_SetSignalCallback(void (*callback)(const char*)) { sh.SetCallback(callback); }
#else #else
/// @brief Sets a callback to a function to run when a signal occurs. /// @brief Sets a callback to a function to run when a signal occurs.
export void Arbutils_C_SetSignalCallback(void (*)(const char*)) { } export_func void Arbutils_C_SetSignalCallback(void (*)(const char*)) { }
#endif #endif

View File

@ -4,7 +4,7 @@
#include <exception> #include <exception>
#include <string> #include <string>
#include "../src/Exception.hpp" #include "../src/Exception.hpp"
#define export extern "C" [[maybe_unused]] #define export_func extern "C" [[maybe_unused]]
#define ArbutilsException 3; #define ArbutilsException 3;

View File

@ -4,35 +4,35 @@
/// @file /// @file
/// @brief Constructs a random class. /// @brief Constructs a random class.
export ArbUt::Random* Arbutils_Random_Construct() { return new ArbUt::Random(); } export_func ArbUt::Random* Arbutils_Random_Construct() { return new ArbUt::Random(); }
/// @brief Constructs a random class with a specific seed. /// @brief Constructs a random class with a specific seed.
export ArbUt::Random* Arbutils_Random_ConstructWithSeed(uint_fast32_t seed) { return new ArbUt::Random(seed); } export_func ArbUt::Random* Arbutils_Random_ConstructWithSeed(uint_fast32_t seed) { return new ArbUt::Random(seed); }
/// @brief Call the destructor on a random object. /// @brief Call the destructor on a random object.
export void Arbutils_Random_Destruct(ArbUt::Random* p) { delete p; } export_func void Arbutils_Random_Destruct(ArbUt::Random* p) { delete p; }
/// @brief Returns a random float between 0.0 and 1.0 using a random object. /// @brief Returns a random float between 0.0 and 1.0 using a random object.
export float Arbutils_Random_GetFloat(ArbUt::Random* p) { return p->GetFloat(); } export_func float Arbutils_Random_GetFloat(ArbUt::Random* p) { return p->GetFloat(); }
/// @brief Returns a random double between 0.0 and 1.0 using a random object. /// @brief Returns a random double between 0.0 and 1.0 using a random object.
export double Arbutils_Random_GetDouble(ArbUt::Random* p) { return p->GetDouble(); } export_func double Arbutils_Random_GetDouble(ArbUt::Random* p) { return p->GetDouble(); }
/// @brief Returns a random a random 32 bit integer using a random object. /// @brief Returns a random a random 32 bit integer using a random object.
export i32 Arbutils_Random_Get(ArbUt::Random* p) { return p->Get(); } export_func i32 Arbutils_Random_Get(ArbUt::Random* p) { return p->Get(); }
/// @brief Gets a random 32 bit integer with a given max. Returns a status code where 0 is Ok, and passes the output to the out parameter. /// @brief Gets a random 32 bit integer with a given max. Returns a status code where 0 is Ok, and passes the output to the out parameter.
export u8 Arbutils_Random_GetWithMax(ArbUt::Random* p, i32 max, i32& out) { Try(out = p->Get(max);) } export_func u8 Arbutils_Random_GetWithMax(ArbUt::Random* p, i32 max, i32& out) { Try(out = p->Get(max);) }
/// @brief Gets a random 32 bit integer with a given min and max. Returns a status code where 0 is Ok, and passes the output to the out parameter. /// @brief Gets a random 32 bit integer with a given min and max. Returns a status code where 0 is Ok, and passes the output to the out parameter.
export u8 Arbutils_Random_GetInLimits(ArbUt::Random* p, i32 min, i32 max, i32& out) { export_func u8 Arbutils_Random_GetInLimits(ArbUt::Random* p, i32 min, i32 max, i32& out) {
Try(out = p->Get(min, max);) Try(out = p->Get(min, max);)
} }
/// @brief Returns a random a random 32 bit unsigned integer using a random object. /// @brief Returns a random a random 32 bit unsigned integer using a random object.
export u32 Arbutils_Random_GetUnsigned(ArbUt::Random* p) { return p->GetUnsigned(); } export_func u32 Arbutils_Random_GetUnsigned(ArbUt::Random* p) { return p->GetUnsigned(); }
/// @brief Gets a random 32 bit unsigned integer with a given max. Returns a status code where 0 is Ok, and passes the output to the out parameter. /// @brief Gets a random 32 bit unsigned integer with a given max. Returns a status code where 0 is Ok, and passes the output to the out parameter.
export u8 Arbutils_Random_GetUnsignedWithMax(ArbUt::Random* p, u32 max, u32& out) { export_func u8 Arbutils_Random_GetUnsignedWithMax(ArbUt::Random* p, u32 max, u32& out) {
Try(out = p->GetUnsigned(max);) Try(out = p->GetUnsigned(max);)
} }
/// @brief Gets a random 32 bit unsigned integer with a given min and max. Returns a status code where 0 is Ok, and passes the output to the out parameter. /// @brief Gets a random 32 bit unsigned integer with a given min and max. Returns a status code where 0 is Ok, and passes the output to the out parameter.
export u8 Arbutils_Random_GetUnsignedInLimits(ArbUt::Random* p, u32 min, u32 max, u32& out) { export_func u8 Arbutils_Random_GetUnsignedInLimits(ArbUt::Random* p, u32 min, u32 max, u32& out) {
Try(out = p->GetUnsigned(min, max);) Try(out = p->GetUnsigned(min, max);)
} }
/// @brief Returns the seed of the random object. /// @brief Returns the seed of the random object.
export uint_fast32_t Arbutils_Random_GetSeed(ArbUt::Random* p) { return p->GetSeed(); } export_func uint_fast32_t Arbutils_Random_GetSeed(ArbUt::Random* p) { return p->GetSeed(); }

View File

@ -4,7 +4,7 @@ project(Arbutils)
include(CPM.cmake) include(CPM.cmake)
# Enable all warnings, and make them error when occurring. # Enable all warnings, and make them error when occurring.
add_compile_options(-Wall -Wextra -Werror) add_compile_options(-Wall -Wextra -Werror -pedantic-errors)
# We like new stuff, so set the c++ standard to c++20. # We like new stuff, so set the c++ standard to c++20.
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
@ -31,7 +31,11 @@ endif (SHARED)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_link_options(-fuse-ld=lld) add_link_options(-fuse-ld=lld)
# Only warn for unknown sanitizers. This error is not major enough to error on. # Only warn for unknown sanitizers. This error is not major enough to error on.
add_compile_options(-Wno-error=unknown-sanitizers) add_compile_options(-Wno-error=unknown-sanitizers -Wno-nullability-extension -Wno-gnu-zero-variadic-macro-arguments)
# Ignore pedantic nullability extension warning, as we only use this for clang specifically
add_compile_options(-Wno-nullability-extension)
# As far as I can tell this is an invalid pedantic warning since C++ 20. Empty variadic macro arguments is completely legal.
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
endif () endif ()
if (CMAKE_BUILD_TYPE MATCHES Release) if (CMAKE_BUILD_TYPE MATCHES Release)

View File

@ -50,9 +50,9 @@
#define ALLOW_UINTEGER_OVERFLOW #define ALLOW_UINTEGER_OVERFLOW
#endif #endif
#define ENUM_WITH_START_VALUE(name, type, startValue, values...) \ #define ENUM_WITH_START_VALUE(name, type, startValue, ...) \
enum class name : type { \ enum class name : type { \
MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(values) - 1, values) \ MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(__VA_ARGS__) - 1, __VA_ARGS__) \
}; \ }; \
class name##Helper { \ class name##Helper { \
ALLOW_UINTEGER_OVERFLOW \ ALLOW_UINTEGER_OVERFLOW \
@ -69,44 +69,46 @@
\ \
public: \ public: \
constexpr static ArbUt::StringViewLiteral ToString(name value) noexcept { \ constexpr static ArbUt::StringViewLiteral ToString(name value) noexcept { \
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \ switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, __VA_ARGS__) } \
return "out of bounds"_cnc; \ return "out of bounds"_cnc; \
} \ } \
constexpr static name Parse(const char* non_null input, bool caseInsensitive = false) { \ constexpr static name Parse(const char* non_null input, bool caseInsensitive = false) { \
if (caseInsensitive) \ if (caseInsensitive) \
return ParseCaseInsensitive(input); \ return ParseCaseInsensitive(input); \
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE, name, values) } \ switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE, name, __VA_ARGS__) } \
throw std::runtime_error("Invalid " #name " string."); \ throw std::runtime_error("Invalid " #name " string."); \
} \ } \
constexpr static bool TryParse(const char* non_null input, name& out, bool caseInsensitive = false) noexcept { \ constexpr static bool TryParse(const char* non_null input, name& out, bool caseInsensitive = false) noexcept { \
if (caseInsensitive) \ if (caseInsensitive) \
return TryParseCaseInsensitive(input, out); \ return TryParseCaseInsensitive(input, out); \
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \ switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE, name, __VA_ARGS__) } \
return false; \ return false; \
} \ } \
static std::vector<name> GetValues() noexcept { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \ static std::vector<name> GetValues() noexcept { \
constexpr static name Last() noexcept { return name::MACRO_UTILS_GET_LAST(values); } \ return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, __VA_ARGS__)}; \
constexpr static name First() noexcept { return name::MACRO_UTILS_GET_FIRST(values); } \ } \
constexpr static name Last() noexcept { return name::MACRO_UTILS_GET_LAST(__VA_ARGS__); } \
constexpr static name First() noexcept { return name::MACRO_UTILS_GET_FIRST(__VA_ARGS__); } \
constexpr static name Highest() noexcept { \ constexpr static name Highest() noexcept { \
i64 highest = -9223372036854775807; \ i64 highest = -9223372036854775807; \
MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, values) \ MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, __VA_ARGS__) \
return (name)highest; \ return (name)highest; \
} \ } \
constexpr static name Lowest() noexcept { \ constexpr static name Lowest() noexcept { \
i64 lowest = 9223372036854775807; \ i64 lowest = 9223372036854775807; \
MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, values) \ MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, __VA_ARGS__) \
return (name)lowest; \ return (name)lowest; \
} \ } \
\ \
private: \ private: \
constexpr static name ParseCaseInsensitive(const char* non_null input) { \ constexpr static name ParseCaseInsensitive(const char* non_null input) { \
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \ switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, __VA_ARGS__) } \
throw std::runtime_error("Invalid " #name " string."); \ throw std::runtime_error("Invalid " #name " string."); \
} \ } \
constexpr static bool TryParseCaseInsensitive(const char* non_null input, name& out) noexcept { \ constexpr static bool TryParseCaseInsensitive(const char* non_null input, name& out) noexcept { \
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \ switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, __VA_ARGS__) } \
return false; \ return false; \
} \ } \
}; };
#define ENUM(name, type, values...) ENUM_WITH_START_VALUE(name, type, 0, values); #define ENUM(name, type, ...) ENUM_WITH_START_VALUE(name, type, 0, __VA_ARGS__);

View File

@ -155,12 +155,8 @@ namespace ArbUt {
}; };
} }
#if !__cpp_consteval
#define consteval constexpr
#endif
#define THROW(message, ...) \ #define THROW(message, ...) \
{ ArbUt::Exception::Throw(message, std::source_location::current(), ##__VA_ARGS__); } { ArbUt::Exception::Throw(message, std::source_location::current() __VA_OPT__(, ) __VA_ARGS__); }
#define NOT_REACHABLE THROW("Not reachable"); #define NOT_REACHABLE THROW("Not reachable");
#define NOT_IMPLEMENTED THROW("Not implemented"); #define NOT_IMPLEMENTED THROW("Not implemented");